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.
Properties
Section titled “Properties”bounds
Section titled “bounds”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
Section titled “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
Methods
Section titled “Methods”follow()
Section titled “follow()”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 })
Parameters
Section titled “Parameters”number | null
options?
Section titled “options?”Returns
Section titled “Returns”void
shake()
Section titled “shake()”shake(
intensity,duration?):void
Shakes the view by up to intensity screen pixels, fading out over duration seconds (default 0.3): hits, explosions.
Parameters
Section titled “Parameters”intensity
Section titled “intensity”number
duration?
Section titled “duration?”number
Returns
Section titled “Returns”void
toWorld()
Section titled “toWorld()”toWorld(
sx,sy):object
Converts screen pixels (e.g. Input.pointer) to world coordinates.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”object
x:
number
y:
number
