BunBunBun Posted March 24, 2015 Share Posted March 24, 2015 I have the following code in the Boot.jsinit: function () { this.game.onPause.add(this.onGamePause, this); this.game.onResume.add(this.onGameResume, this);},onGamePause: function() { console.log('onGamePause'); if (!MainGame.supportAudio) return; game.sound.mute = true;},onGameResume: function() { console.log('onGameResume'); if (!MainGame.supportAudio) return; game.sound.mute = false;}, then, I call "pause game" in the Game.js for example like that: pauseGame: function () { MainGame.isPaused = !MainGame.isPaused; game.paused = MainGame.isPaused; if(MainGame.isMusicMuted){ game.sound.setMute(); }else{ game.sound.unsetMute(); }} and then, when the browser/tab loss focus, onGamePause and onGameResume don't work. main goal: to continue to play music after calling pauseGame, it's done as you see, but if the browser/tab loss focus - mute music. Link to comment Share on other sites More sharing options...
rich Posted March 25, 2015 Share Posted March 25, 2015 What about disabling the visibility check? (the thing that makes it auto-pause when it loses focus). Then you could handle it yourself. Link to comment Share on other sites More sharing options...
BunBunBun Posted March 26, 2015 Author Share Posted March 26, 2015 if I made "disableVisibilityChange = true",this code will not work:this.game.onPause.add(this.onGamePause, this);this.game.onResume.add(this.onGameResume, this);and how I can check out the losing focus on game? Link to comment Share on other sites More sharing options...
BunBunBun Posted March 26, 2015 Author Share Posted March 26, 2015 easy way to do: add the option "no mute sound if game.paused" to Engine,rich, what do you think? Link to comment Share on other sites More sharing options...
BunBunBun Posted March 27, 2015 Author Share Posted March 27, 2015 up Link to comment Share on other sites More sharing options...
rich Posted April 1, 2015 Share Posted April 1, 2015 But then people will ask for "don't stop animations when the game is paused" etc I think the issue is a bit of a naming one - it's more like Phaser itself is paused, not just your game, which is why audio stops, etc. You can override what happens by replacing the Game functions:Phaser.Game.prototype.gamePaused = function (event) { // If the game is already paused it was done via game code, so don't re-pause it if (!this._paused) { this._paused = true; this.time.gamePaused(); //this.sound.setMute(); this.onPause.dispatch(event); }};So it replaces the gamePaused handler. You can do the same for gameResumed too. Then you can control what happens and why. Link to comment Share on other sites More sharing options...
BunBunBun Posted April 1, 2015 Author Share Posted April 1, 2015 thanks! it's a good idea to override gamePaused function. Link to comment Share on other sites More sharing options...
Recommended Posts