Skip to content

Game

The running game: its world, resources, systems, scenes and loop. Created by createGame.

readonly canvas: HTMLCanvasElement


readonly fixedAlpha: number

How far the frame is between the last fixed tick and the next, 0–1. The renderer uses it to draw Interpolate entities between their last two fixed-tick transforms, so physics looks smooth on 120 Hz screens.


readonly fixedDt: number


readonly height: number


readonly viewport: Readonly<Viewport>

Where the game is drawn on the canvas, in canvas pixels (renderers and overlays use it).


readonly width: number

The game’s size in screen pixels (see GameOptions.size). Place HUDs and menus with it, not with the canvas.


readonly world: World

get<T>(key): T

T

Token<T>

T


scene(scene): Promise<void>

Switches to a scene: removes the systems the previous scene registered, runs its cleanup and despawns every entity, then runs the new scene. Systems and resources from plugins stay. Call it again with the same scene to restart it. For hot reload during development: import.meta.hot?.accept('./level', (m) => m && game.scene(m.level))

Scene

Promise<void>


set<T>(key, value): void

T

Token<T>

T

void


start(): void

void


step(dt): void

Advances one frame manually; useful in tests and environments without requestAnimationFrame.

number

void


stop(): void

void


system(fn, stage?): () => void

Registers a system; returns a function that removes it (tweens and timers remove themselves when done).

System

Stage

() => void


toScreen(clientX, clientY): object

Converts a point on the page (clientX, clientY of a mouse or touch event) to screen pixels.

number

number

object

x: number

y: number