Camera2D
The orthographic camera of a Scene2D. Every scene owns one — access it as
scene.camera; you never construct a Camera2D yourself.
At a glance
const scene = new Scene2D()
scene.camera.zoom = 2 // 2× magnification — pixel-art friendly
// keep the camera on the hero, with a little easing
setLoop(dt => {
scene.camera.position = scene.camera.position.lerp(hero.worldPosition, 10 * dt)
})Transform
camera.position = [x, y] // world units — the point at the center of the screen
camera.zoom = 2 // magnification; at 1, 1 world unit = 1 logical px. Default 1
camera.rotation = 15 // degrees, CCW. Default 0Getters return fresh values (camera.position.x = 3 is a no-op — see
conventions).
Note
there is no built-in follow(). Track a node from setLoop (as above) or with a
small update(dt) aspect — nothing to dispose when the target goes away.
Screen ↔ world
camera.screenToWorld(screenX, screenY): Vec2 // logical px → world units
camera.worldToScreen(worldX, worldY): Vec2 // world units → logical pxscreenToWorld is the pairing for tap handling: convert ev.clientX/clientY and feed the result
to scene.pick() or Physics2D.overlapPoint(). Remember the sign flip:
screen Y points down, world Y points up — the conversion handles it for you.
See also
- Scene2D — the owning scene,
pick() - 2D physics —
overlapPoint,raycast - Pointer events & gestures —
clientX/clientYare logical px