Skip to content

Commit 8c41f6c

Browse files
committed
Game.onBlur and Game.onFocus events are now dispatched regardless if Stage.disableVisibilityChange is true or false, so you can respond to these events without your game automatically pausing or resuming (phaserjs#911)
1 parent 2916f04 commit 8c41f6c

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Version 2.0.6 - "Jornhill" - -in development-
7676
* Loader.isLoading is set to false if the filelist size is zero.
7777
* Sound.externalNode has had the `input` property dropped from it, bringing it back in line with the AudioNode spec (thanks @villetou, #840)
7878
* The StateManager has a preRenderCallback option, which checks for a preRender function existing on the State, but it was never called. Have decided to add this in, so the core Game loop now calls state.preRender right before the renderer runs (thanks @AnderbergE #869)
79+
* Game.onBlur and Game.onFocus events are now dispatched regardless if Stage.disableVisibilityChange is true or false, so you can respond to these events without your game automatically pausing or resuming (#911)
7980

8081
### CocoonJS Specific Updates
8182

src/core/Game.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,10 @@ Phaser.Game.prototype = {
787787

788788
this.onBlur.dispatch(event);
789789

790-
this.gamePaused(event);
790+
if (!this.stage.disableVisibilityChange)
791+
{
792+
this.gamePaused(event);
793+
}
791794

792795
},
793796

@@ -802,7 +805,10 @@ Phaser.Game.prototype = {
802805

803806
this.onFocus.dispatch(event);
804807

805-
this.gameResumed(event);
808+
if (!this.stage.disableVisibilityChange)
809+
{
810+
this.gameResumed(event);
811+
}
806812

807813
}
808814

src/core/Stage.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,12 @@ Phaser.Stage.prototype.checkVisibility = function () {
287287

288288
/**
289289
* This method is called when the document visibility is changed.
290+
*
290291
* @method Phaser.Stage#visibilityChange
291292
* @param {Event} event - Its type will be used to decide whether the game should be paused or not.
292293
*/
293294
Phaser.Stage.prototype.visibilityChange = function (event) {
294295

295-
if (this.disableVisibilityChange)
296-
{
297-
return;
298-
}
299-
300296
if (event.type === 'pagehide' || event.type === 'blur' || event.type === 'pageshow' || event.type === 'focus')
301297
{
302298
if (event.type === 'pagehide' || event.type === 'blur')
@@ -311,6 +307,11 @@ Phaser.Stage.prototype.visibilityChange = function (event) {
311307
return;
312308
}
313309

310+
if (this.disableVisibilityChange)
311+
{
312+
return;
313+
}
314+
314315
if (document.hidden || document.mozHidden || document.msHidden || document.webkitHidden)
315316
{
316317
this.game.gamePaused(event);

0 commit comments

Comments
 (0)