How to keep musc looping even after resetting the world?


(John Andersson) #1

I’ve tried various methods, but none of them seem to work. I tried adding an entity which plays the music, I tried adding the music directly in the game world… I feel lost? Resetting the world seems to restart the music no matter what I do


(Darrin) #2

John,

I just use a static sound manager which I call in my Title World Update.

			if (!bMusicStarted){
			SoundManager.theme();
			bMusicStarted = true;
		}

Here is the class it calls.

	import net.flashpunk.Sfx;
/**
 * ...
 * @author Darrin Adams
 */
public class SoundManager 
{
	private static var sfxCrash:Sfx;
	private static var sfxTheme:Sfx;
	private static var sfxPoints:Sfx;
	private static var sfxLeague:Sfx;
	private static var sfxShark:Sfx;
	private static var sfxChallengeStart:Sfx;
	private static var sfxChallengeSuccess:Sfx;
	private static var sfxCrunch:Sfx;
	
	
	private static var bMute:Boolean = false;
	
	public function SoundManager() 
	{
		sfxCrash = new Sfx(Main.sound.getSound("CRASH"));
		sfxTheme = new Sfx(Main.sound.getSound("THEME"));
		sfxPoints = new Sfx(Main.sound.getSound("POINTS"));
		sfxLeague = new Sfx(Main.sound.getSound("LEAGUE"));
		sfxShark = new Sfx(Main.sound.getSound("SHARK"));
		sfxChallengeStart = new Sfx(Main.sound.getSound("CHALLENGESTART"));
		sfxChallengeSuccess = new Sfx(Main.sound.getSound("CHALLENGESUCCESS"));
		sfxCrunch = new Sfx(Main.sound.getSound("BREAK"));
	}
	
	public static function crash():void { if (!bMute) sfxCrash.play(0.3); }
	public static function theme():void { if (!bMute) sfxTheme.loop(0.3) else sfxTheme.stop(); }
	public static function points():void { if (!bMute) sfxPoints.play(0.3); }
	public static function league():void { if (!bMute) sfxLeague.play(0.3); }
	public static function shark():void { if (!bMute) sfxShark.play(0.3); }
	public static function challengeStart():void { if (!bMute) sfxChallengeStart.play(0.3); }
	public static function challengeSuccess():void { if (!bMute) sfxChallengeSuccess.play(0.3); }
	public static function crunch():void { if (!bMute) sfxCrunch.play(0.3); }
	
	public static function getMute():Boolean {
		return bMute;
	}
	
	public static function mute():void {
		bMute = true;									
		theme();						
	}
	public static function unMute():void {
		bMute = false;									
		theme();						
	}
}