The GameContext & runtime
Every game setup(ctx) receives a GameContext (packages/engine/src/runtime/types.ts)
— the one object through which you reach the whole engine.
What’s in the context
Section titled “What’s in the context”| Group | Fields |
|---|---|
| Raw libraries | scene, camera, rapierWorld, rapier, composer |
| Engine managers | input, collisions, physics, audio, particles, debugDraw, animGraphs, assets, systems, components |
| UI | uiContainer |
The raw libraries are the real Three.js / Rapier objects — call them directly. The managers bridge what a raw library doesn’t provide (the Object3D↔body map, system phases, the component manager, and so on).
The setup function
Section titled “The setup function”A game’s setup(ctx) registers systems / loads scenes / sets up state and returns a
GameCleanup ({ dispose() }). Every setup must return a dispose that removes
everything it created — the scene switcher calls it on change.
Runtime & session lifecycle
Section titled “Runtime & session lifecycle”createGameRuntime(...) boots the engine and returns a GameSession to control it:
stop()— full teardown.pause()/resume()— freeze / unfreeze time (viatimeScale).step()— advance a single fixed tick while paused.resize(width, height)— resize renderer + camera.- read-only getters for
scene,camera, andmounted(the underlying mounted game).
When launched from the editor’s play mode, setup also receives an EditorPreview
(scenePath, in-memory sceneData with unsaved edits, and the viewportCamera transform) so
the running game matches what you’re editing.
Debug draw
Section titled “Debug draw”ctx.debugDraw (packages/engine/src/dev/debug-draw.ts) is an immediate-mode helper, cleared
each frame:
line(from, to, color?),sphere(center, radius?, color?),box(center, size, color?),arrow(origin, direction, length?, color?);clear()and avisibletoggle.
See also
Section titled “See also”- Entities & components — what
ctxis passed to. - The game loop & phases — when systems run.
- Tooling & Publishing — hot reload and the editor session.