Jump to content

Destroying sounds - best practice


Doug
 Share

Recommended Posts

Hi all

I am using Angular 4 and creating an interface which has a number of games.  They load in a modal (i.e. no page refresh/change) and I then destroy them with this.phaserGame.destroy(true);

I have background audio that I am playing with the following:

preload () : void
{
  this.load.audio('bg', [
    this.p('audio/bg.mp3'),
    this.p('audio/bg.ogg')
  ]);
}

this.p() just gets the relative path.

create () : void
{
  this.sound_bg = this.sound.add('bg', { loop: true });
}

When I destroy and reload the game, the background audio object seems to still be in the DOM and plays over itself on second game launch.

I've had a look through the documentation and tried removeByKey() remove() and destroy() in the BaseSoundManager() namespace just before destroying the game.

None of these seem to solve the problem though.

What is best practice for completely destroying sounds please?

Thank you!

Link to comment
Share on other sites

  • 2 months later...

Thanks very much @samme - I am actually using the latest version of Phaser, but I just had another look at my code.  It's pretty complicated in there now and it looks like there was one instance where I wasn't destroying the game properly, but just closing the modal.  I've amended it now and so far it appears to have done the trick.  So I'll do some more testing.  

Thank you and sorry for wasting your time if it was this.

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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