Skip to content

Commit

Permalink
Fix broken handling of multi-touch input
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Schürz committed Jan 17, 2025
1 parent 62d43f8 commit 4f0a2c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/framework/src/input/InputManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Drawable } from '../graphics/drawables/Drawable';
import type { GameHost } from '../platform/GameHost';
import type { UIEvent } from './events/UIEvent';
import type { InputHandler } from './handlers/InputHandler';
import type { TouchSource } from './handlers/Touch';
import type { IFocusManager } from './IFocusManager';
import type { InputStateChangeEvent } from './stateChanges/events/InputStateChangeEvent';
import type { IInput } from './stateChanges/IInput';
Expand All @@ -25,6 +24,7 @@ import { HoverLostEvent } from './events/HoverLostEvent';
import { MouseMoveEvent } from './events/MouseMoveEvent';
import { ScrollEvent } from './events/ScrollEvent';
import { KeyboardHandler } from './handlers/KeyboardHandler';
import { TouchSource } from './handlers/Touch';
import { KeyEventManager } from './KeyEventManager';
import { MouseButtonEventManager } from './MouseButtonEventManager';
import { InputState } from './state/InputState';
Expand Down Expand Up @@ -611,6 +611,9 @@ export abstract class InputManager extends Container implements IInputStateChang
if (!this.mapMouseToLatestTouch)
return false;

if (e.touch.source !== TouchSource.Touch1)
return false;

if (e.isActive === true || e.lastPosition !== null) {
new MousePositionAbsoluteInputFromTouch(e, e.touch.position).apply(this.currentState, this);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/framework/src/input/handlers/MouseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export class MouseHandler extends InputHandler {
#handleMouseMove = (event: PointerEvent) => {
event.preventDefault();

if (event.pointerType === 'touch')
return;

const rect = (event.target as HTMLCanvasElement).getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
Expand Down
5 changes: 3 additions & 2 deletions packages/framework/src/input/handlers/TouchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ export class TouchHandler extends InputHandler {
#handleTouchStart = (event: TouchEvent) => {
event.preventDefault();

const touches = this.#getTouches(event, event.changedTouches);
const touches = this.#getTouches(event, event.touches);
if (touches.length === 0)
return;

this.#enqueueTouch(new TouchInput(touches, true));
this.flush.emit();
if (event.type === 'touchstart')
this.flush.emit();
};

#handleTouchEnd = (event: TouchEvent) => {
Expand Down

0 comments on commit 4f0a2c0

Please sign in to comment.