UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

50 lines (49 loc) 1.57 kB
import Camera from "../camera/camera"; import Object2D from "../object2d"; import Controls from "./controls"; export default class TouchControls extends Controls { anchor: Touch; /** * Creates a {@link TouchControls} instance and sets up it's event handlers. * * @param element The element to use when handling control events * @param camera The camera to control * @param object An optional object to follow the camera's yaw * @param sensitivity Movement sensitivity */ constructor(element: HTMLElement, camera: Camera, object?: Object2D, sensitivity?: number); /** * Finds the first touch targeting `this.element`. * * @param touches The list of touches to choose from * @returns The first touch targeting `this.element` or undefined */ private findTouchTargetingElement; /** * Sets the anchor point to the first touch detected when anchor has not already been set. * * @param e The touch event */ private touchStartHandler; /** * Calculates the difference in position from the last anchor and the current touch point. * * These values are then set in `movementX` and `movementY`. * * @param e The touch event */ private touchMoveHandler; /** * Removes the touch anchor. * * @param e The touch event */ private touchEndHandler; /** * Calculates the new camera direction from `movementX` and `movementY`. * * Called every tick. */ update(): void; dispose(): void; }