What it does
Objects live on named layers, by default back, world and front, drawn back to front. Within a layer they draw
by z, then in spawn order. Nothing is sorted by height on screen, because in a platformer a hero standing higher is
not further away; you say what is in front.
It installs the shared 2D camera, with pan, zoom and bounds, and toWorld and toScreen to convert between screen
pixels and world units, so a tap finds its place in the level. view, vw and vh give the rectangle the camera
is looking at and points a fraction across it, read fresh each time so they are never a frame behind.
Set wrap and the world becomes a torus. Positions wrap, everything draws at its nearest image to the camera, the
camera follows across the seam, and nearby-object queries and collisions see across it too. Game code never wraps a
coordinate itself; the engine does it after every step.
Features
- Declared depth — layer, then
z, then spawn order, with no surprises from position. - Your own layers — name as many as the game needs; spawning on an unknown layer throws, so a typo is caught at once.
- The 2D camera — pan, zoom and bounds, with
toWorldandtoScreen. - View helpers —
view,vwandvhfor placing things relative to what the camera sees. - Wrap-around worlds —
wrap: { w, h }makes positions, drawing, the camera, queries and collision cross the edges.
Good for
- Platformers — declared depth for scenery, level and foreground, with gravity and platforms from physics.
- Endless runners — a camera that pans along with the runner across the level.
- Horizontal and vertical scrolling shooters — layers for the backdrop, the action and the effects in front.
- Brick breakers and bat-and-ball games — a fixed playfield with its depth set by layer.
- Wrap-around space arenas — ships and rocks that fly off one edge and in at the other, in the style of Asteroids.
Make it yours
The options are the layer list and the wrap size. A platformer might declare its own layers for the sky, the
distant hills, the level and the effects in front, with the camera bounded to the level and following the hero. A
single-screen arena sets wrap to the size of the screen, so everything that leaves one edge comes back at the other,
and the game never writes a line of wrapping code.
A quick look
A cloud behind, a hero over the same layer's other objects, and a tap converted into the world:
game.spawn({ id: 'cloud', x, y, layer: 'back' });
game.spawn({ id: 'hero', x, y, layer: 'world', z: 1 }); // over same-layer z:0
const p = game.input.pointer; // screen pixels
if (p) { const at = game.world.toWorld(p.x, p.y); /* … */ }
Works with
core-2dandcore-vector— both compose it, so most 2D games have it already.physics-2d— gravity and platforms;tiles-2d— a tilemap for the level.rig-follow— the camera that follows the player;controls-2d— the input.world-screen— a HUD over it, and an underlay that sits just above its first layer.world-topdown— the alternative when characters should walk behind things by standing higher on screen.
Good to know
- Two objects with the same layer and
zdraw in spawn order, and nothing reorders them. - Wrapping is all or nothing: a level that wraps only horizontally needs a wide world and a bounds clamp instead.
- The 2D camera does not rotate.
- There is one 2D world per game.






