API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classView

@codexo/exojs / rendering / stable

2D camera that defines what region of the world is visible on screen. Maintains a center position, a visible area size, a rotation, and an optional zoom level. Provides lazy-evaluated world-to-clip and clip-to-world transform matrices, a follow-target system for tracking scene nodes, and a procedural screen-shake effect. Call update once per frame to advance follow and shake animations.

9
props
29
methods
0
events
Import
import { View } from '@codexo/exojs'

2D camera that defines what region of the world is visible on screen.

Maintains a center position, a visible area size, a rotation, and an optional zoom level. Provides lazy-evaluated world-to-clip and clip-to-world transform matrices, a follow-target system for tracking scene nodes, and a procedural screen-shake effect. Call update once per frame to advance follow and shake animations.

Constructors1
new(centerX: number, centerY: number, width: number, height: number): View
Methods29
clearBounds(): this
clearFollow(): this
clearShake(): this
destroy(): void
Release the math objects this view owns. Idempotent - the same view can be reachable from more than one owner (a RenderTarget it was assigned to as well as the code that created it), so a second call must not take _center, _size, _viewport and the cached matrices through a second teardown.
Track a scene node or world position each frame. The view center is interpolated towards the target using the lerp factor. Call clearFollow to stop tracking.
Return the world-space bounding rectangle of the currently visible area, recalculating if dirty. Used for frustum culling by Drawable.render. Pass out to receive a copy you own. Without it the return value is this view's cached rectangle, which the next recalculation overwrites in place.
Return the cached clip-to-world inverse matrix, recalculating it if dirty. Use this to convert screen-space coordinates (e.g. mouse position) to world space.
Return the cached world-to-clip projection matrix, recalculating it if dirty. The returned matrix is owned by this view - do not store a reference across frames.
move(x: number, y: number): this
reset(centerX: number, centerY: number, width: number, height: number): this
resize(width: number, height: number): this
Resize the view to the given dimensions and reset zoom to 1. Use this when the canvas or window is resized.
rotate(degrees: number): this
Convert a logical/design-space pixel coordinate to a world-space position. The 2-argument form treats (x, y) as coordinates in the view's own design space (0..view.width × 0..view.height) - the same space as Pointer.x/Pointer.y and node positions - and applies only the inverse camera transform. The viewport rectangle is intentionally ignored, because design-space input already lives inside the camera's projection - the mapping from the surface to logical pixels happened upstream. At the default centered camera this is the identity.
screenToWorld(screenX: number, screenY: number, canvasWidth: number, canvasHeight: number): PointLikeStructural type for any object with a 2D `x`/`y` position.
Convert a raw canvas backing-store pixel coordinate to a world-space position. Accounts for the view's viewport rectangle, so it works correctly in multi-view / split-screen and letterboxed setups.
Constrain the camera center so the visible area never extends outside bounds. When the view is larger than the constraint rectangle the camera is clamped to the geometric centre of the rectangle. Pass null to remove the constraint.
setCenter(x: number, y: number): this
setRotation(degrees: number): this
setViewport(x: number, y: number, width: number, height: number): this
Set the normalized (0..1) viewport rectangle fluently. Mirrors the set viewport property setter without allocating a Rectangle - pass the four components directly.
setZoom(zoom: number): this
Set an absolute zoom level. A zoom of 2 halves the visible area; 0.5 doubles it. Values are clamped to a minimum of 0.0001 to prevent division by zero.
Start a procedural camera shake effect. The shake applies a sinusoidal offset to the view's center position, then stops automatically when duration elapses. Call clearShake to cancel early.
update(deltaMilliseconds: number): this
updateBounds(): this
updateTransform(): this
worldToScreen(worldX: number, worldY: number): PointLikeStructural type for any object with a 2D `x`/`y` position.
Convert a world-space position to logical/design-space pixel coordinates (0..view.width × 0..view.height). Inverse of the 2-argument screenToWorld; the viewport is ignored. At the default centered camera this is the identity.
worldToScreen(worldX: number, worldY: number, canvasWidth: number, canvasHeight: number): PointLikeStructural type for any object with a 2D `x`/`y` position.
Convert a world-space position to raw canvas backing-store pixel coordinates. Accounts for the view's viewport rectangle.
zoom(factor: number): this
zoomIn(amount: number): this
zoomOut(amount: number): this
Create a View from a ViewOptions bag. All options are optional and default to the same values as a bare new View(0, 0, 0, 0) call with a full-canvas viewport and no rotation or zoom.
Properties9
destroyed: boolean
true once destroy has run. A destroyed view keeps its last computed transform but no longer reacts to mutations - its center stops marking the transform stale - so it must not be put back into use.
height: number
rotation: number
updateId: number
Monotonically increasing counter incremented whenever the view's transform is invalidated. Backends use this to detect when to re-upload the projection matrix.
The normalized (0..1) viewport rectangle this camera renders into. Returns the LIVE rectangle, and writing to it directly - view.viewport.x = 0.5, view.viewport.set(...), view.viewport.size.width = ... - is a supported way to move the viewport: the rectangle reports every mutation back here, so updateId advances exactly as it does for setViewport. Backends key their "may I keep the open pass" decision on that counter, and a viewport is a property of the pass as a whole.
width: number
zoomLevel: number
Source