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 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;

View File

@ -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);