zencha Posted March 2, 2015 Share Posted March 2, 2015 Hey guys, I begin playing some music on my Menu state and then I have a "store" state where the player can shop. I want the music to continue playing if the player switches between the main menu and the store state. Strange thing is, this was working previously. I probably broke it, but I can't figure out how because there's no code on the the store state about music. Link to comment Share on other sites More sharing options...
MichaelD Posted March 3, 2015 Share Posted March 3, 2015 are you adding the music like this: this.add.track(...);If so try to add it like thisgame.add.track(...);where game is your global game object. This way it is globally viewable across states. Link to comment Share on other sites More sharing options...
zencha Posted March 4, 2015 Author Share Posted March 4, 2015 I think I'm doing it correctly? My code is:else if (this.menuMusic.isPlaying == false) { this.menuMusic = game.add.audio('musicSwag'); this.menuMusic.loop = true; this.menuMusic.volume = 1; this.playMusic(); } Link to comment Share on other sites More sharing options...
valueerror Posted March 4, 2015 Share Posted March 4, 2015 well that's how i do it and it works: in my preload state i call this in the create function:music1 = game.add.audio('theme2',1,true); in the game states i call this:if (!music1.isPlaying){ music1.play('',0,1,true); } the music starts playing and never stops"music1" is global... maybe that's it ? marius98 1 Link to comment Share on other sites More sharing options...
antn9x Posted October 19, 2016 Share Posted October 19, 2016 Hi, I have the same issue, did you fix it? I add music to game and play it on create function in other states. But it didn't take effect. this.game.music = this.game.add.audio('theme', 1, true); and if(!this.game.music) this.game.music = this.game.add.audio('theme', 1, true); if(this.game.music.isPlaying == false) this.game.music.play(); Link to comment Share on other sites More sharing options...
Recommended Posts