Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Need some clarification on the SoundManager


buttonsrtoys
 Share

Recommended Posts

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 find

game.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

Rich, so is it OK to call

game.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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...