Jump to content

Music not properly stopping


zencha
 Share

Recommended Posts

Hey guys,

 

I just added a store screen to my menu, so I have the Main Menu state and Store state. 

 

I set it to play a song on Main Menu and to continue playing that audio regardless of which of those two states the player is in. 

 

If you hit the Main Menu and then begin the actual Play state, the Menu music stops properly and the Play music begins.

 

However, if I enter the Store state, return to the Main Menu, and then go to the Play state, the Main Menu music does not stop and continues to play over the Play state.

 

How do I get the music to properly stop when entering the Play state?

 

Relevant code:

 

Load.js

     create: function(){            game.global.menuMusicPlaying = false;            game.state.start('menu');      }};

Menu.js:

this.menuMusic = game.add.audio('music');            this.menuMusic.loop = true;            this.menuMusic.volume = 1;            this.playMusic();playMusic: function () {            if(game.global.menuMusicPlaying == true){                  return;            }            else {                  this.menuMusic.play();            }            game.global.menuMusicPlaying = true;      }
      start: function(){            this.menuMusic.stop();            game.state.start('play');      },
Link to comment
Share on other sites

Finally got it to work with some help.

// Create, play, and loop the menu music if there is none            if(this.menuMusic == null) {                  this.menuMusic = game.add.audio('music');                  this.menuMusic.loop = true;                  this.menuMusic.volume = 1;                  this.playMusic();            }            // Restarts the menu music when Play state returns to Menu            else if (this.menuMusic.isPlaying == false) {                  this.playMusic();            }

Properly stops and starts where intended now. Woo!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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