Skip to content
Snippets Groups Projects
Commit 7e9f6568 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe pause/resume gain depending on focus

parent 95964be4
No related branches found
No related tags found
No related merge requests found
...@@ -23,4 +23,24 @@ const config = { ...@@ -23,4 +23,24 @@ const config = {
scene: [BackgroundScene, WelcomeScene, FightScene, GameOverScene], scene: [BackgroundScene, WelcomeScene, FightScene, GameOverScene],
}; };
new Phaser.Game(config); const game = new Phaser.Game(config);
const pauseGame = function (this: Phaser.Game) {
this.scene
.getScenes(true)
.filter((scene) => !scene.scene.isPaused())
.forEach((scene) => scene.scene.pause());
};
game.events.on(Phaser.Core.Events.BLUR, pauseGame, game);
game.events.on(Phaser.Core.Events.HIDDEN, pauseGame, game);
const resumeGame = function (this: Phaser.Game) {
this.scene
.getScenes(false)
.filter((scene) => scene.scene.isPaused())
.forEach((scene) => scene.scene.resume());
};
game.events.on(Phaser.Core.Events.FOCUS, resumeGame, game);
game.events.on(Phaser.Core.Events.VISIBLE, resumeGame, game);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment