Changing map without changing the background music

39 views
Skip to first unread message

JustGabe

unread,
Dec 2, 2015, 10:48:39 PM12/2/15
to HaxeFlixel
Yesterday I programmed my game so that when the char walks into an "exit tile", the FlxG.switchState is called and the map is redrawn, the problem with this approach is that the music also resets.  Maybe it's too much to ask if there's a way for the music to continue playing through the different states, so I tried by recalling the create function and failed, tried to rewrite the variables (map, chars, items, etc.) and nothing.

Any suggestions of how to redraw everything without the need of "switching states" so that the music can go indefinitely until the "zone" changes (kinda like any RPG where you get inside the house and the music is still playing, but when getting out of the town, the music switches)?

Thank you!

Seb Jones

unread,
Dec 3, 2015, 6:58:33 AM12/3/15
to HaxeFlixel
In your state's create function, try checking that the music isn't already playing, like so:

if (FlxG.sound.music == null || !FlxG.sound.music.playing)
{
   
//PLAY MUSIC HERE
}
Reply all
Reply to author
Forward
0 new messages