UNPKG

blaze-2d

Version:

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

76 lines (75 loc) 2.14 kB
import { vec2 } from "gl-matrix"; import RectCollider from "../physics/collider/rect"; /** * Represents a {@link Camera}'s viewable area and can be used to perform culling. */ export default class Viewport { private originalWidth; private originalHeight; private width; private height; private centre; /** * Creates a {@link Viewport} instance. * * @param centre The centre of the viewport in world space * @param width The width of the viewport in world space * @param height The height of the viewport in world space */ constructor(centre: vec2, width: number, height: number); /** * Calculates the viewports bounds around a given centre. * * @param centre The centre of the viewport */ update(centre: vec2): void; /** * Checks wether the provided rectangle collider is contained within the viewport. * * TODO: Change this to use physics collision system so it works with more than just RectCollider * * @param rect The rect to check * @returns Wether or not the box is withing the viewport */ containsRectCollider(rect: RectCollider, worldToPixelScale: vec2): boolean; /** * Sets the viewport's width. * * @throws When width is <= 0 * * @param width The viewport's new width */ setWidth(width: number): void; /** * Gets the viewport's width. * * @returns The viewport's width */ getWidth(): number; /** * Sets the viewport's height. * * @throws When height is <= 0 * * @param height The viewport's new height */ setHeight(height: number): void; /** * Gets the viewport's height. * * @returns The viewport's height */ getHeight(): number; /** * Gets the width the viewport was given when constructed. * * @returns The viewport's original width */ getOriginalWidth(): number; /** * Gets the height the viewport was given when constructed. * * @returns The viewport's original height */ getOriginalHeight(): number; }