Jump to content

Correct handling of multiple musics

Tom Atom

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:


 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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