Skip to main content

CameraWrapper

@zylem/game-lib


@zylem/game-lib / core / CameraWrapper

Class: CameraWrapper

Defined in: packages/game-lib/src/lib/camera/camera.ts:72

CameraWrapper is the user-facing camera handle returned by createCamera(). It provides convenience methods for target management, orbital controls, viewport configuration, and the camera pose pipeline.

Constructors​

Constructor​

new CameraWrapper(camera): CameraWrapper

Defined in: packages/game-lib/src/lib/camera/camera.ts:75

Parameters​

camera​

ZylemCamera

Returns​

CameraWrapper

Properties​

cameraRef​

cameraRef: ZylemCamera

Defined in: packages/game-lib/src/lib/camera/camera.ts:73

Methods​

addAction()​

addAction(action): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:159

Add a transient action (screenshake, recoil, etc.). Actions apply additive deltas and self-expire when isDone() returns true.

Parameters​

action​

CameraAction

Returns​

void


addBehavior()​

addBehavior(key, behavior): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:142

Add or replace a behavior by key (idempotent). Behaviors modify the desired camera pose each frame.

Parameters​

key​

string

Unique key for this behavior (used for replacement/removal).

behavior​

CameraBehavior

The CameraBehavior implementation.

Returns​

void


addTarget()​

addTarget(entity): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:85

Add a target entity for the camera to follow/frame. With multiple targets, the camera auto-frames to include all of them.

Parameters​

entity​

StageEntity

Returns​

void


clearTargets()​

clearTargets(): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:99

Clear all targets. Camera will look at world origin.

Returns​

void


disableOrbitalControls()​

disableOrbitalControls(): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:116

Disable orbital controls for this camera.

Returns​

void


enableOrbitalControls()​

enableOrbitalControls(): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:109

Enable orbital controls for this camera. Allows the user to orbit, pan, and zoom the camera.

Returns​

void


getPerspective()​

getPerspective<T>(): T

Defined in: packages/game-lib/src/lib/camera/camera.ts:184

Retrieve the active perspective instance, cast to the desired type. Useful for calling perspective-specific methods (e.g. FirstPersonPerspective.look()).

Type Parameters​

T​

T extends CameraPerspective = CameraPerspective

Returns​

T

Example​

const fps = camera.getPerspective<FirstPersonPerspective>();
fps.look(dx, dy);

getRenderTexture()​

getRenderTexture(): Texture<unknown, TextureEventMap> | null

Defined in: packages/game-lib/src/lib/camera/camera.ts:205

Get the offscreen render texture for this camera. Returns null if the camera was not created with renderToTexture. Use with setCameraFeed() or apply directly to a mesh material.

Returns​

Texture<unknown, TextureEventMap> | null


getState()​

getState(): CameraPipelineState

Defined in: packages/game-lib/src/lib/camera/camera.ts:194

Return a debug snapshot of the camera pipeline state. Includes: active perspective, desired/final pose, behavior keys, action count.

Returns​

CameraPipelineState


removeBehavior()​

removeBehavior(key): boolean

Defined in: packages/game-lib/src/lib/camera/camera.ts:149

Remove a behavior by key.

Parameters​

key​

string

Returns​

boolean


removeTarget()​

removeTarget(entity): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:92

Remove a target entity from the camera.

Parameters​

entity​

StageEntity

Returns​

void


setPerspective()​

setPerspective(type, options?): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:172

Switch the camera's active perspective at runtime. The first frame after switching snaps to the new pose (no lerp).

Parameters​

type​

PerspectiveType

Perspective type string (e.g. Perspectives.ThirdPerson).

options?​

PerspectiveOptions

Perspective-specific options (distance, height, zoom, etc.).

Returns​

void


setViewport()​

setViewport(x, y, width, height): void

Defined in: packages/game-lib/src/lib/camera/camera.ts:129

Set the viewport for this camera (normalized 0-1 coordinates).

Parameters​

x​

number

Left edge (0 = left of canvas)

y​

number

Bottom edge (0 = bottom of canvas)

width​

number

Width as fraction of canvas

height​

number

Height as fraction of canvas

Returns​

void