Jump to content

Correct handling of multiple musics


Tom Atom
 Share

Recommended Posts

Hi, I would like to ask how to correctly start and end music. Whan I want to start playing of music I call play method of SoundManager:

game.sound.play(aMusicName, aVolume, aLoop);

 I found, that internally it first calls add method and inside it creates Phaser.Sound object and pushes it into _sounds array. When I want to change to different music, I call the same code but with different music name. It again creates another Phaser.Sound object and again it pushes it into _sounds array. After many switches from main menu of the game (where 1st music is playing) to game (where 2nd music is playing), the _sound array has many entries, which I think is not correct.

 

 I found that I can avoid this if I call this when stopping music:

game.sound.remove(MyGame.music);game.sound.removeByKey(MyGame.musicName);

 Then the Phaser.Sound object is destroyed and removed from SoundManager's _sound array. But, is this correct way to do if you want to switch between multiple musics?

 

 

 I could bypass SoundManager when I want to play music by calling play directly on Phaser.Sound object. This will not create entry in _sounds array. But there is no way how to ask SoundManager for Phaser.Sound later - so it would mean to store all references on frist play or add call...

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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