Build a multi-root game β a 3D root with a 2D overlay
site/media/lessons/learn-multiworld.lesson.ts (5 steps) A vgai game is a manifest-backed adapter-root list: vgai.game.json can declare any
number of threejs, pixijs, and react adapters, and one Game mounts them as stacked
layers β one shared loop, per-root zOrder, each root with its own scene and its own
components. In this lesson you build the classic shape: a 3D world with a 2D HUD overlay
above it, then edit both through one editor session. (Concept reference:
Multi-world games & play control.)
-
Press Play. One
Gamemounts the root list: the Three.js root renders on the bottom canvas, and the pixijs overlay stacks above it (zOrder: 10) on its own transparent canvas β you see the yellow sprite floating over the 3D scene.
Two worlds, one Game: the pixijs overlay's canvas stacks above the threejs canvas. -
Read the hierarchy. The hierarchy shows native Three.js and PixiJS roots, with each rootβs entities beneath it.
Native adapter roots organize their own entities. -
Select the cube in the threejs world. The inspector shows its transform like any entity β the same panels you know from single-world editing.
-
Select the sprite in the pixijs overlay. The same hierarchy + inspector route to the 2D world:
HudBadgeshows 2D position, scale, alpha, and tint.
The same panels drive the 2D world β position, alpha, tint. -
Edit Position-Y and save. Change the spriteβs
Position Yto240. In a multi-world session, play-mode edits persist to per-world overlay files β this one lands in.vgai/overlays/overlay.jsonin your project, keyed by the world id.
The edit persists to the overlay world's own file: .vgai/overlays/overlay.json.
Cross-world code works the same way: game.queryByComponent(Cls) spans every first-party
world in one call (narrow with {worldId} or {kind}). And the world node is the
entity in every kind β Object3D in threejs worlds, PIXI.Container in pixijs worlds.
Recap
New functionality
- Declared a two-world game (threejs + pixijs overlay) in vgai.game.json
- Played it β two stacked canvases, one Game, one loop
- Inspected entities in both worlds and persisted a 2D edit to the world's overlay file
New concepts & skills
- a game is a manifest-backed adapter-root list mounted by one Game
- roots stack as layers by zOrder; upper canvases are transparent
- the hierarchy presents native adapter roots
- multi-root play edits persist per root
Next lesson β Pause, resume & step
On Your Own!
Extend what you built:
- Add a second pixijs overlay at zOrder 20 and watch the layer order
- Give the 2D scene more sprites and tint them from the inspector
- Add a react world to the list β see the React worlds tutorial