Class Camera

A simple 2D camera, which optionally snaps position values to pixels.

Hierarchy (view full)

Constructors

Properties

bounds: null | CameraBounds = null
modelView: Matrix4 = ...

The model view matrix of this camera. Do not modify outside of camera code.

projection: Matrix4 = ...

The projection matrix of this camera. Do not modify outside of camera code.

snapToPixel: boolean = true

If set to true, the position will be snapped to pixels.

viewportHeight: number = 0
viewportWidth: number = 0
x: number = 0
y: number = 0
zoom: number = 1

Methods

  • Returns number

    The current viewport height.

  • Returns number

    The current viewport width.

  • Returns number

    The current x position of the camera (before snapping to pixels).

  • Returns number

    The current y position of the camera (before snapping to pixels).

  • Returns number

    The zoom value of the camera.

  • Move the camera to the specified coordinates and apply pixel snapping if configured.

    Parameters

    • x: number

      The new x position of the camera.

    • y: number

      The new y position of the camera.

    Returns void

  • Set the new viewport size of the camera.

    Parameters

    • width: number

      The new width of the viewport.

    • height: number

      The new height of the viewport.

    Returns void

  • Set camera bounds.

    Parameters

    • bounds: null | CameraBounds

      The new bounds or null to remove the current bounds.

    Returns void

  • Set the camera to the specified coordinates and apply pixel snapping if configured.

    Parameters

    • x: number

      The new x position of the camera.

    • y: number

      The new y position of the camera.

    Returns void

  • Set the zoom value and update the projection matrix accordingly.

    Parameters

    • zoom: number

      The new zoom value.

    Returns void

  • Update the projection matrix to adjust for new viewport size or zoom value.

    Returns void