Skip to content

Commit

Permalink
making sure the game still runs when unfocused
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Sep 16, 2021
1 parent 8efa7cc commit 788c02e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 0 additions & 1 deletion example/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const game = new Phaser.Game({
parent: 'game',
scaleMode: Phaser.ScaleManager.SHOW_ALL,
state: { preload, create, update },
disableVisibilityChange: true,
backgroundColor: '#333',
});

Expand Down
9 changes: 4 additions & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 788c02e

Please sign in to comment.