Skip to content

Camera

2D camera: x/y is the world point at the center of the screen, zoom scales world pixels. The default view (centered on the canvas, zoom 1) maps world coordinates 1:1 to screen pixels.

bounds: CameraBounds | null

World rectangle the view stays inside, such as the level’s edges; null (the default) for none. When the view is bigger than the rectangle, the camera centers on it. camera.bounds = { x: 0, y: 0, width: map.width, height: map.height }


height: number


width: number

View size in screen pixels; the renderer keeps it in sync with the game’s size.


x: number


y: number


zoom: number

follow(e, options?): void

Keeps an entity in view, where the renderer draws it (so Interpolate entities stay smooth). It stops when the entity is despawned; camera.follow(null) stops it too. camera.follow(player, { lerp: 0.1 })

number | null

FollowOptions

void


shake(intensity, duration?): void

Shakes the view by up to intensity screen pixels, fading out over duration seconds (default 0.3): hits, explosions.

number

number

void


toWorld(sx, sy): object

Converts screen pixels (e.g. Input.pointer) to world coordinates.

number

number

object

x: number

y: number