From 42a3b7daf8a9af1ddf89ba9155a96ce73dd0d1a8 Mon Sep 17 00:00:00 2001 From: Mathieu Hermann Date: Wed, 1 Jan 2025 22:34:33 +0100 Subject: [PATCH] refactor(touch-manage): add a fix to resetting when up zone is different that down zone --- src/app/game/utils/touch-manager.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/app/game/utils/touch-manager.ts b/src/app/game/utils/touch-manager.ts index 6425221..635c69e 100644 --- a/src/app/game/utils/touch-manager.ts +++ b/src/app/game/utils/touch-manager.ts @@ -55,15 +55,30 @@ export class TouchManager { private recomputeTouchStatus(type: 'down' | 'up', position: Vector): void { if (this.getTouchZone(position) === 'back') { + if (!this.isTouchingBack && type === 'up') { + this.resetTouching(); + } this.isTouchingBack = type === 'down'; } else if (this.getTouchZone(position) === 'left') { + if (!this.isTouchingLeft && type === 'up') { + this.resetTouching(); + } this.isTouchingLeft = type === 'down'; } else if (this.getTouchZone(position) === 'right') { + if (!this.isTouchingRight && type === 'up') { + this.resetTouching(); + } this.isTouchingRight = type === 'down'; } this.isTouching = this.isTouchingBack || this.isTouchingLeft || this.isTouchingRight; } + private resetTouching(): void { + this.isTouchingBack = false; + this.isTouchingLeft = false; + this.isTouchingRight = false; + } + private getTouchZone(position: Vector): 'back' | 'left' | 'right' { if (position.y > window.innerHeight - Config.TOUCH_BRAKE_ZONE_RATIO * window.innerHeight) { return 'back';