Music that persists between level transitions [SOLVED]


(Vince Betteridge) #1

Hey all,

I need help. I have a music track I want to persist between levels. As far as I know “removeAll();” is what is deleting the track each time I load the level. My attempt to have everything removed excluding the music looks something like this.

import net.flashpunk.FP;
import net.flashpunk.World;
import net.flashpunk.Sfx;

public var music:Sfx = Sfx(Assets.MUSIC);
public var nonMusicList:Array = new Array;
        
getAll(nonMusicList);
FP.remove(nonMusicList, ???);
        
removeList(nonMusicList);

This method does not seem to be correct at all in solving the problem. I have no idea what would go in the ??? as the music is not a class. Even if I leave out the “FP.remove(nonMusicList, ???);” the “removeList(nonMusicList);” does not remove everything the same way “removeAll();” does.

The music is playing great right now if I use “removeAll();” I just want it to not be interrupted between levels.

Any help is appreciated, -VinceB


(Bora Kasap) #2

that’s the world class. Why don’t you try to handle your music fx on a global static class?


(Vince Betteridge) #3

Thank you! That was all I needed to hear. For anyone else who needs a more detailed look at what I did I will post it.

Assets Class:

[Embed(source = "../assets/sfx/music.mp3")] public static const MUSIC:Class;

Global Class:

public static const music:Sfx = new Sfx(Assets.MUSIC);

Game Class:

Global.music.loop();

(Mike Evmm) #4

(As often discussed on this forum, global statics are a touchy feely subject. Just wanted to say to use them carefully)