blaze-2d
Version:
A fast and simple WebGL 2 2D game engine written in TypeScript
68 lines (67 loc) • 1.81 kB
TypeScript
import Camera from "../../camera/camera";
import { Mouse } from "../../input/mouse";
/**
* Allows the camera to be panned, zoomed and rotated.
*
* By default the middle mouse button is used for panning, scroll for zoom and arrow keys for rotation.
*/
export default class EditorCameraControls {
camera: Camera;
private canvas;
panButton: Mouse;
private isPanPressed;
private last;
zoomSensitivity: number;
rotateSpeed: number;
posRotateKey: string;
negRotateKey: string;
/**
* Create an {@link EditorCameraControls} instance.
*
* @param camera The camera to control
* @param canvas The canvas to attach event listeners to
*/
constructor(camera: Camera, canvas: HTMLCanvasElement);
/**
* Enables panning when the mouse button is pressed.
*
* @param e The mouse event
*/
private onMousedown;
/**
* Disables panning when the mouse button is released.
*
* @param e The mouse event
*/
private onMouseup;
/**
* Moves the camera by the difference between the current and last mouse position.
*
* @param e The mouse event
*/
private onMousemove;
/**
* Zooms/unzooms the camera.
*
* @param e The wheel event
*/
private onWheel;
/**
* Rotates the camera on key down.
*
* @param e The keyboard event
*/
private onKeydown;
/**
* Set the canvas to be attach event listeners to.
*
* @param canvas The {@link HTMLCanvasElement} to attach event listeners to
*/
setCanvas(canvas: HTMLCanvasElement): void;
/**
* Get the canvas that event listeners are on.
*
* @returns The canvas that event listeners are attached to
*/
getCanvas(): HTMLCanvasElement;
}