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

feat: #fe pause for mobile

parent e16ccf84
No related branches found
No related tags found
No related merge requests found
...@@ -157,10 +157,7 @@ export default class FightScene extends Phaser.Scene { ...@@ -157,10 +157,7 @@ export default class FightScene extends Phaser.Scene {
} }
async create() { async create() {
const escBinding = this.input.keyboard.addKey( this.bindPauseShortcut();
Phaser.Input.Keyboard.KeyCodes.ESC,
);
escBinding.onDown = () => this.scene.pause();
this.gameTime = this.time.addEvent({ this.gameTime = this.time.addEvent({
delay: Number.MAX_SAFE_INTEGER, delay: Number.MAX_SAFE_INTEGER,
...@@ -444,4 +441,21 @@ export default class FightScene extends Phaser.Scene { ...@@ -444,4 +441,21 @@ export default class FightScene extends Phaser.Scene {
// NOTE: pretty please, don't access the timer directly. // NOTE: pretty please, don't access the timer directly.
return Math.round(this.gameTime.getElapsed()); return Math.round(this.gameTime.getElapsed());
} }
bindPauseShortcut() {
if (this.game.device.os.desktop) {
const escBinding = this.input.keyboard.addKey(
Phaser.Input.Keyboard.KeyCodes.ESC,
);
escBinding.onDown = () => this.scene.pause();
} else {
const onPointerUp = (pointer: Phaser.Input.Pointer) => {
const tapped =
pointer.downY <
this.cameras.main.height - this.uiDimensions.kbdHeight;
if (tapped) this.scene.pause();
};
this.input.on("pointerup", onPointerUp);
}
}
} }
...@@ -9,7 +9,7 @@ export default class PauseScene extends Phaser.Scene { ...@@ -9,7 +9,7 @@ export default class PauseScene extends Phaser.Scene {
this.drawShade(); this.drawShade();
this.drawTitle(); this.drawTitle();
this.drawCTA(); this.drawCTA();
this.bindEvents(); this.bindResumeShortcut();
} }
drawShade() { drawShade() {
...@@ -51,10 +51,14 @@ export default class PauseScene extends Phaser.Scene { ...@@ -51,10 +51,14 @@ export default class PauseScene extends Phaser.Scene {
); );
} }
bindEvents() { bindResumeShortcut() {
const escBinding = this.input.keyboard.addKey( if (this.game.device.os.desktop) {
Phaser.Input.Keyboard.KeyCodes.ESC, const escBinding = this.input.keyboard.addKey(
); Phaser.Input.Keyboard.KeyCodes.ESC,
escBinding.onDown = () => this.scene.resume("fight"); );
escBinding.onDown = () => this.scene.resume("fight");
} else {
this.input.on("pointerup", () => this.scene.resume("fight"));
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment