Jump to content

Proper way to stop sound playback on state transition?


QLNEO
 Share

Recommended Posts

All I need is to stop all sound playback before I load another state.

I have this music playing at the menu, and I'm having trouble when transitioning into the main game. It goes as follows: music intro and music loop are separated files; intro plays once, and its onStop event has a listener that plays the loop (on loop, of course). If I do nothing, when state changes, the playback won't stop (even though clearWorld parameter is true), and it'll attempt to loop as well.

If I use game.sound.destroy() before starting the new state, "An attempt was made to use an object that is not, or is no longer, usable". Maybe it has to do with the fact that I'm using, as a placeholder, the menu music in the main game, but fact is, even if I load the audio file again in preload(), it just doesn't let me play and crashes. :/

Link to comment
Share on other sites

Yeah, that was the ticket. Embarassingly enough, that even crossed my mind, but I was afraid that it would mess up with the onStop listener I set to the intro, but I knew I could just remove the listener before. By then that simple thought already went away and I tried going with removeAll() instead.

Thanks again :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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