blaze-2d
Version:
A fast and simple WebGL 2 2D game engine written in TypeScript
55 lines (54 loc) • 1.58 kB
TypeScript
import { vec2 } from "gl-matrix";
import Object2D from "../object2d";
import Viewport from "./viewport";
/**
* Represents the camera in 2D world space.
*
* The camera's position is the centre of the viewport.
*/
export default class Camera extends Object2D {
viewport: Viewport;
private zoomLevel;
minZoom: number;
maxZoom: number;
lastPos: vec2;
/**
* Creates a {@link Camera} instance and instantiates its {@link Viewport} with a width and height at the camera's centre.
*
* @param centre The centre of the camera's viewport
* @param vw The camera's viewport width
* @param vh The camera's viewport height
*/
constructor(centre: vec2, vw: number, vh: number);
/**
* Creates a {@link Camera} instance and sets its viewport.
*
* @param centre The centre of the camera's viewport
* @param viewport The viewport to use with the camera
*/
constructor(centre: vec2, viewport: Viewport);
/**
* Updates the camera's viewport if the camera has changed position since the last call to update.
*/
update(): void;
/**
* Zooms the camera by the given amount.
*
* @param zoom The amount to zoom by
*/
zoom(zoom: number): void;
/**
* Sets the zoom level of the camera.
*
* This will change the size of `this.viewport`.
*
* @param zoom The zoom level
*/
setZoom(zoom: number): void;
/**
* Gets the zoom level of the camera.
*
* @returns The zoom level of the camera
*/
getZoom(): number;
}