Areg Posted June 15, 2014 Share Posted June 15, 2014 I want to detect the visibility change in my game ( that is, when , for instance, browser tab loses focus, for example). I know that when that occurs, Phaser automatically pauses my whole game system. I want to prevent that automatic pausing, but still I want to receive signal/event about this visibility change. Link to comment Share on other sites More sharing options...
j0hnskot Posted June 15, 2014 Share Posted June 15, 2014 The one part you want is Stage.disableVisibilityChange . By setting this to true the game will not pause.But by looking in source i can't see if it is possible to launch onBlur and onFocus events with disableVisibilityChange. I may be wrong. Areg 1 Link to comment Share on other sites More sharing options...
Areg Posted June 15, 2014 Author Share Posted June 15, 2014 I am listening to game.onPause event. that only works if stage.disablevisibilityChange is false. Other than game.onPause, I do not know about any other event that says that browser lost control that I can listen to Link to comment Share on other sites More sharing options...
Areg Posted June 15, 2014 Author Share Posted June 15, 2014 when stage.disbleVisibilityChange is true, onBlur and onFocus events are not being fired, as expected But there has to be some other way to prevent game from auto pausing Link to comment Share on other sites More sharing options...
j0hnskot Posted June 15, 2014 Share Posted June 15, 2014 If this is a critical production feature you could hack the source a bit for now until someones points out the correct way to do so.Look at phaser.js .Comment out line 20136 and line 20151 ( this.gamePaused(event); and this.gameResumed(event) ; and then go to line16449, cut the if (this.disableVisibilityChange) { return; }and paste it above this located at line 16468 if (document.hidden || document.mozHidden || document.msHidden || document.webkitHidden) { this.game.gamePaused(event); } else { this.game.gameResumed(event); }This should fire the onBlur and Onfocus events with disableVisibilityChange=true . Test it and let me know. Keep in mind that this is a BAD approach. You should keep your eyes in this thread for someone with a better solution. Areg 1 Link to comment Share on other sites More sharing options...
Areg Posted June 15, 2014 Author Share Posted June 15, 2014 ah, it works. onBlur events are fired normally and there seems to be no auto pausing , thanks a lot Link to comment Share on other sites More sharing options...
Recommended Posts