Skip to content

Commit

Permalink
refactor(touch-manage): add a fix to resetting when up zone is differ…
Browse files Browse the repository at this point in the history
…ent that down zone
  • Loading branch information
mathieuher committed Jan 1, 2025
1 parent 48e8973 commit 42a3b7d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/app/game/utils/touch-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 42a3b7d

Please sign in to comment.