buttonsrtoys Posted September 7, 2015 Share Posted September 7, 2015 I'm a bit confused about managing sounds in my game. Simply put, I'd like to add a dozen sounds and be able to play and stop them as necessary. After lifting some some code from the examples, I"m loading sounds to my game with game.load.audio('thruster', ['assets/thruster.mp3']);and playing them with game.sound.play('thruster');but I'm not seeing a 'stop' method. There is a 'stopAll' method, but I just want to stop a specific sound. I did findgame.sound.removeByKey('thruster');which works, but it removes it from the manager and then 'play' adds it back? Does that mean if I use 'play' dozens of times, it will add dozens of instances to the game? If someone could clarify, or better yet, tell me which calls I should be using, I'd be indebted. Link to comment Share on other sites More sharing options...
rich Posted September 8, 2015 Share Posted September 8, 2015 var thrust = game.sound.play('thruster'); thrust.stop(); Link to comment Share on other sites More sharing options...
buttonsrtoys Posted September 8, 2015 Author Share Posted September 8, 2015 Rich, so is it OK to callgame.sound.play('thruster');thousands of times without calling 'remove' or 'stop' or is that chewing up memory? Most of my sound effects don't need to be stopped. Link to comment Share on other sites More sharing options...
mcolman Posted September 8, 2015 Share Posted September 8, 2015 That's fine, you don't need to call stop, it won't chew up memory. Link to comment Share on other sites More sharing options...
rich Posted September 9, 2015 Share Posted September 9, 2015 Rich, so is it OK to callgame.sound.play('thruster');thousands of times without calling 'remove' or 'stop' or is that chewing up memory? Most of my sound effects don't need to be stopped. Every time you call SoundManager.play (which is what the line above does) it will create a brand new Phaser.Sound object, so you want to keep this down really. I'd suggest you add a reference for the sounds you need a lot (this.thrustFx = this.sound.play('thrust')) and then call thrustFx.play over and over instead. This will keep the Sound object count down. buttonsrtoys 1 Link to comment Share on other sites More sharing options...
Recommended Posts