Sound effects stop if the same sound is being played before it is finished (playing a sound more than once resets it before it is finished)


(John Andersson) #1

Pretty much explained it in the title :stuck_out_tongue:

If two bricks fall shortly after each other, the sound doesn’t fully play twice, it plays once, then doesn’t finish, then plays again.

I’m using the standard way of playing sound effects, I want to be able to “stack” the same sound with itself


(Ben Pettengill) #2

If you’re only creating one instance of each sound effect (like in this tutorial), then a new instance of the sound will stop one that’s already playing; If you don’t want the second sound to cancel out the first, you;ll want to create a new instance of the sound effect every time you play it.

What I usually do is import all my sounds into one class, then have a static function that I can call to play them:

    package  
    {
    
    	public class Assets 
    	{
    		import net.flashpunk.Sfx;
    
    		//Mp3 sounds:
    		[Embed(source = '../assets/snd_bonus.mp3')]
    		public static const snd_bonus:Class;
    
    		public function Assets() 
    		{
    		
    		}
    
        		public static function playMp3(whatmp3:Class, _vol:Number = 1, _pan:Number = 0):void {
    			var snd:Sfx = new Sfx(whatmp3); 
    			snd.play(_vol * ((Math.exp(Global.volume / 10) - 1) / (Math.E-1)), _pan);
    		}
    	}
}

This will create a new instance of every sound that you play.


(John Andersson) #3

How weird, I did what you said but it doesn’t work. The same problem persists. I double checked and everything is as it should be :S


(Ben Pettengill) #4

That should work. Can you post the code you use for playing sounds?