Skip to content

Commit

Permalink
fix(touch-manager): fix the scrolling touch that was blocking skier a…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
mathieuher committed Dec 7, 2024
1 parent 768b2f9 commit 84a3dbb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/app/game/utils/touch-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Config } from '../config';
export class TouchManager {
private engine: Engine;

private activePointers: Map<number, 'back' | 'left' | 'right'> = new Map();

public isTouching = false;
public isTouchingBack = false;
public isTouchingLeft = false;
Expand All @@ -16,22 +18,25 @@ export class TouchManager {

private listenTouch(): void {
this.engine.input.pointers.on('down', event => {
this.recomputeTouchStatus('down', event.pagePos);
this.recomputeTouchStatus(event.pointerId, 'down', event.pagePos);
});

this.engine.input.pointers.on('up', event => {
this.recomputeTouchStatus('up', event.pagePos);
this.recomputeTouchStatus(event.pointerId, 'up', event.pagePos);
});
}

private recomputeTouchStatus(type: 'down' | 'up', position: Vector): void {
if (this.getTouchZone(position) === 'back') {
this.isTouchingBack = type === 'down';
} else if (this.getTouchZone(position) === 'left') {
this.isTouchingLeft = type === 'down';
} else if (this.getTouchZone(position) === 'right') {
this.isTouchingRight = type === 'down';
private recomputeTouchStatus(pointerId: number, type: 'down' | 'up', position: Vector): void {
if (type === 'down') {
this.activePointers.set(pointerId, this.getTouchZone(position));
} else {
this.activePointers.delete(pointerId);
}

this.isTouchingBack = this.activePointers.get(pointerId) === 'back';
this.isTouchingLeft = this.activePointers.get(pointerId) === 'left';
this.isTouchingRight = this.activePointers.get(pointerId) === 'right';

this.isTouching = this.isTouchingBack || this.isTouchingLeft || this.isTouchingRight;
}

Expand Down

0 comments on commit 84a3dbb

Please sign in to comment.