TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/fraxel/llms.txt
Use this file to discover all available pages before exploring further.
<camera> node controls what portion of the game world is visible by applying a viewport transform to everything it contains. Place the camera at the root of your scene tree and add all world objects as its children — the camera then translates, scales, and clips the canvas so that the camera’s position maps to the centre of the screen.
Basic Usage
Props
| Prop | Type | Default | Description |
|---|---|---|---|
position | VectorLike | [0, 0] | Camera position in world space. The point that maps to screen centre |
zoom | number | 1 | Zoom level. 2 makes everything appear twice as large; 0.5 zooms out |
SignalGetter to either for live updates without calling any methods.
Following a Target
Callcamera.node.follow(target) to make the camera continuously track a node’s globalPosition. Pass undefined to stop following and return to manual position control.
Methods
| Method | Description |
|---|---|
follow(target) | Makes the camera track the target node’s globalPosition every frame |
follow(undefined) | Stops following; the camera uses its own position property instead |
How the Transform Works
Each frame, before drawing its children, the camera performs four canvas operations:- Translate to centre —
ctx.translate(width / 2, height / 2). The world origin is now at the middle of the screen. - Scale by zoom —
ctx.scale(zoom, zoom). Applies the zoom factor. - Translate by
-position—ctx.translate(-posX, -posY)whereposX/posYis either the camera’s ownpositionor the followed target’sglobalPosition. - Draw children — all child nodes render into the transformed context.
ctx.restore(), so nothing outside the camera’s subtree is affected.
Scrolling World Example
The following side-scroller follows the player but switches to a fixed position when the player is too close to the left edge of the level:useEvent listener fires every frame (the 'updated' event) and reads the player’s world position. When the player is within 96 px of the left edge, follow(undefined) disengages target tracking and the camera’s own position is set directly. Once the player moves further right, follow(player.node) re-engages.
For movement and physics that drive the player node, see Physics. For the hooks used here, see API: Hooks (Core).