From 0d2b1902222b244869a2eee93693496bea92cb3a Mon Sep 17 00:00:00 2001 From: GRL Date: Fri, 4 Jun 2021 09:39:33 +0200 Subject: [PATCH] Replace setTimeout by timer manage in Update --- front/src/Phaser/Login/SelectCharacterScene.ts | 13 +++++++++++-- front/src/Phaser/Login/SelectCompanionScene.ts | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/front/src/Phaser/Login/SelectCharacterScene.ts b/front/src/Phaser/Login/SelectCharacterScene.ts index b56e38f5..052e5900 100644 --- a/front/src/Phaser/Login/SelectCharacterScene.ts +++ b/front/src/Phaser/Login/SelectCharacterScene.ts @@ -32,6 +32,7 @@ export class SelectCharacterScene extends AbstractCharacterScene { protected selectCharacterSceneElement!: Phaser.GameObjects.DOMElement; protected currentSelectUser = 0; protected pointerClicked: boolean = false; + protected pointerTimer: number = 0; protected lazyloadingAttempt = true; //permit to update texture loaded after renderer @@ -137,13 +138,16 @@ export class SelectCharacterScene extends AbstractCharacterScene { repeat: -1 }); player.setInteractive().on("pointerdown", () => { - if (this.pointerClicked || this.currentSelectUser === i) { + if (this.pointerClicked) { + return; + } + if (this.currentSelectUser === i) { return; } this.pointerClicked = true; + this.pointerTimer = 250; this.currentSelectUser = i; this.moveUser(); - setTimeout(() => {this.pointerClicked = false;}, 250); }); this.players.push(player); } @@ -243,6 +247,11 @@ export class SelectCharacterScene extends AbstractCharacterScene { } update(time: number, delta: number): void { + this.pointerTimer -= delta; + if (this.pointerTimer <= 0) { + this.pointerClicked = false; + } + if(this.lazyloadingAttempt){ this.moveUser(); this.lazyloadingAttempt = false; diff --git a/front/src/Phaser/Login/SelectCompanionScene.ts b/front/src/Phaser/Login/SelectCompanionScene.ts index 8f641a3a..b240a553 100644 --- a/front/src/Phaser/Login/SelectCompanionScene.ts +++ b/front/src/Phaser/Login/SelectCompanionScene.ts @@ -24,6 +24,7 @@ export class SelectCompanionScene extends ResizableScene { private currentCompanion = 0; private pointerClicked: boolean = false; + private pointerTimer: number = 0; constructor() { super({ @@ -73,7 +74,10 @@ export class SelectCompanionScene extends ResizableScene { } update(time: number, delta: number): void { - + this.pointerTimer -= delta; + if (this.pointerTimer <= 0) { + this.pointerClicked = false; + } } public selectCompanion(): void { @@ -110,9 +114,9 @@ export class SelectCompanionScene extends ResizableScene { return; } this.pointerClicked = true; + this.pointerTimer = 250; this.currentCompanion = i; this.moveCompanion(); - setTimeout(() => {this.pointerClicked = false;}, 250) }); this.companions.push(companion);