I'm making my first game with Gosu and it's great so far! Truly amazing!
Also note that I'm fairly new to Ruby so if I do anything strange below, it's probably because I don't know the normal Ruby practices yet.
(I'm using OS X Lion with Ruby 1.9.2)
My problem is this: I have several levels in my game and when a level change, I want to change the music.
I'm using Gosu::Song and have got a couple of mp3-tracks but for some reason, when the level changes, the music plays for a second or two then stops.
It looks to me that when one reference-variable which points to Gosu::Song is being removed by the garbage collector, the music stops for some reason (even though I have made a new reference variable).
This is a problem since I have a separate class for each level, and if I have a variable pointing to Gosu::Song and the level-object is removed the music stops even though the next level-object is currently "running" and have it's own music-variable pointing to Gosu::Song. (Sorry if this is a somewhat strange explanation).
So I've been able to avoid this by taking out the reference-variables from the level-classes and simply put them in the main file (which I do not want to do).
I have the same problem here where the music stops if the reference variable is removed.
So to give an example (not so pretty, but so you know what I'm talking about):
@music = Gosu::Song.new(self, "sfx/track1.mp3")
if @currentLevel.done then
@music.stop # Doesn't seem to be necessary
@music2 = Gosu::Song.new(self, "sfx/track2.mp3")
#@music = nil
So this works, but if I uncomment "@music = nil" the music stops after about a second or two which doesn't make sense to me.
If I replace @music2 with @music and reuse the variable, it's the same problem.
And I don't want to create new variables like this and keep the old one for each new song. I must be doing something weird here.
What am I doing wrong - how should this be handled? Thanks!
Maybe just try:
I don't know if it will work better, but Gosu automatically references currently played song (at least on Windows)
It seems like the music stops playing after ~1 second if I do it, even on the first track.
Ouch. You've made a bug pretty obvious that was reported once before AFAIK.
When any OGG song is deleted, any song being played will stop as well. I recommend just leaving all songs cached in a global Hash for now.
If you just told me 5 hours earlier... ;) Will fix this in the next version.
Hehe I see!
Well, working with a hash works so I'm happy for now :)
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill