From 788c02e81c408cffbf6eca4a2af949163f55745a Mon Sep 17 00:00:00 2001 From: Kleber Silva Date: Thu, 16 Sep 2021 01:44:30 -0300 Subject: [PATCH] making sure the game still runs when unfocused --- example/game.js | 1 - src/plugin.ts | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/example/game.js b/example/game.js index 5ed28f0..c99a6c6 100644 --- a/example/game.js +++ b/example/game.js @@ -5,7 +5,6 @@ const game = new Phaser.Game({ parent: 'game', scaleMode: Phaser.ScaleManager.SHOW_ALL, state: { preload, create, update }, - disableVisibilityChange: true, backgroundColor: '#333', }); diff --git a/src/plugin.ts b/src/plugin.ts index c237a78..5834093 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -4,14 +4,10 @@ import Phaser from 'phaser-ce'; export class Plugin extends Phaser.Plugin { private readonly editorWindow: EditorWindow; - - private root: Container; - private refImage?: PIXI.Sprite; + private _disableVisibilityChangeMemento: boolean; public constructor(game: Phaser.Game, root?: Container, refImage?: PIXI.Sprite) { super(game, game.plugins); - this.root = root; - this.refImage = refImage this.insertHead(); this.editorWindow = new EditorWindow(game, root, refImage); @@ -43,11 +39,14 @@ export class Plugin extends Phaser.Plugin { private onEditorShow() { (this as any).postUpdate = this._postUpdate.bind(this); + this._disableVisibilityChangeMemento = this.game.stage.disableVisibilityChange; + this.game.stage.disableVisibilityChange = true; this.hasPostUpdate = true; } private onEditorHide() { this.hasPostUpdate = false; + this.game.stage.disableVisibilityChange = this._disableVisibilityChangeMemento; (this as any).postUpdate = null; }