Pause, resume & step — play control with per-world pausable
site/media/lessons/learn-playcontrol.lesson.ts (4 steps) Game.play is the one game-level control surface: pause, resume, and step,
with per-world "pausable" semantics. The classic use is a pause menu: the simulation
freezes, but the menu world declares "pausable": false and keeps running. The editor’s
play bar drives this surface directly — so does the CLI (vgai pause / vgai resume /
vgai step). (Concept reference:
Multi-world games & play control.)
-
Press Play. Both worlds run: the teal cube spins in the
simworld (pausable by default), the orange square spins in themenuoverlay ("pausable": false).
Two worlds, one loop — the play bar's pause and step buttons drive Game.play. -
Pause. The play bar’s pause button calls
game.play.pause(). Every pausable world freezes — the teal cube stops mid-turn. The menu world is exempt: the orange square keeps spinning, because the loop itself never stops.
Pause freezes pausable worlds; pausable: false keeps ticking. -
Step. Each click of the step button calls
game.play.step()— it advances exactly the frozen worlds by one fixed substep. The teal cube creeps forward one frame per click; the menu world is untouched (the still-running loop already ticks it).
Step advances only the frozen worlds — one fixed substep per click. -
Resume. The inverse of pause; both are idempotent. The teal cube spins again.
Recap
New functionality
- Paused, resumed, and single-stepped a running two-world game from the play bar
- Exempted a menu overlay from pause with "pausable": false
- Watched Step advance exactly the frozen world, one fixed substep per click
New concepts & skills
- Game.play is the one game-level control surface (editor play bar and CLI both drive it)
- pausable is per-world; false keeps a menu/HUD world ticking through pause
- the loop never stops — frozen worlds render with dt = 0
- step() advances only frozen worlds and is a no-op while unpaused
Next lesson → React worlds
On Your Own!
Extend what you built:
- Mark the sim world pausable: false too and see pause become a visual no-op
- Drive the same controls from the CLI: vgai pause, vgai step, vgai resume
- Put a falling physics body in the sim world and single-step the fall