Replace setTimeout by timer manage in Update

This commit is contained in:
GRL 2021-06-04 09:39:33 +02:00
parent 8052877a7b
commit 0d2b190222
2 changed files with 17 additions and 4 deletions

View File

@ -32,6 +32,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
protected selectCharacterSceneElement!: Phaser.GameObjects.DOMElement; protected selectCharacterSceneElement!: Phaser.GameObjects.DOMElement;
protected currentSelectUser = 0; protected currentSelectUser = 0;
protected pointerClicked: boolean = false; protected pointerClicked: boolean = false;
protected pointerTimer: number = 0;
protected lazyloadingAttempt = true; //permit to update texture loaded after renderer protected lazyloadingAttempt = true; //permit to update texture loaded after renderer
@ -137,13 +138,16 @@ export class SelectCharacterScene extends AbstractCharacterScene {
repeat: -1 repeat: -1
}); });
player.setInteractive().on("pointerdown", () => { player.setInteractive().on("pointerdown", () => {
if (this.pointerClicked || this.currentSelectUser === i) { if (this.pointerClicked) {
return;
}
if (this.currentSelectUser === i) {
return; return;
} }
this.pointerClicked = true; this.pointerClicked = true;
this.pointerTimer = 250;
this.currentSelectUser = i; this.currentSelectUser = i;
this.moveUser(); this.moveUser();
setTimeout(() => {this.pointerClicked = false;}, 250);
}); });
this.players.push(player); this.players.push(player);
} }
@ -243,6 +247,11 @@ export class SelectCharacterScene extends AbstractCharacterScene {
} }
update(time: number, delta: number): void { update(time: number, delta: number): void {
this.pointerTimer -= delta;
if (this.pointerTimer <= 0) {
this.pointerClicked = false;
}
if(this.lazyloadingAttempt){ if(this.lazyloadingAttempt){
this.moveUser(); this.moveUser();
this.lazyloadingAttempt = false; this.lazyloadingAttempt = false;

View File

@ -24,6 +24,7 @@ export class SelectCompanionScene extends ResizableScene {
private currentCompanion = 0; private currentCompanion = 0;
private pointerClicked: boolean = false; private pointerClicked: boolean = false;
private pointerTimer: number = 0;
constructor() { constructor() {
super({ super({
@ -73,7 +74,10 @@ export class SelectCompanionScene extends ResizableScene {
} }
update(time: number, delta: number): void { update(time: number, delta: number): void {
this.pointerTimer -= delta;
if (this.pointerTimer <= 0) {
this.pointerClicked = false;
}
} }
public selectCompanion(): void { public selectCompanion(): void {
@ -110,9 +114,9 @@ export class SelectCompanionScene extends ResizableScene {
return; return;
} }
this.pointerClicked = true; this.pointerClicked = true;
this.pointerTimer = 250;
this.currentCompanion = i; this.currentCompanion = i;
this.moveCompanion(); this.moveCompanion();
setTimeout(() => {this.pointerClicked = false;}, 250)
}); });
this.companions.push(companion); this.companions.push(companion);