Scene lifecycle

Scenes are game-owned lifecycle objects. Mounting is asynchronous and atomic, active scenes update and draw from the bottom of the stack to the top, and removing a scene disposes it permanently.

status: loading

base updates: 0

overlay updates: 0

Public shape

const handle = await game.scenes.mount(({ signal }) => ({
  name: "menu",
  init: async () => {
    if (signal.aborted) return;
  },
  update: (time) => {},
  draw: () => {},
}));

await game.scenes.remove(handle);

What this demonstrates

The example mounts two independent scenes into one game and reports their update counts. Scene factories also receive the game-owned typed event bus through context.events; use it for explicit scene communication without a global singleton. The shared manifest asset remains usable while one scene leaves. Scene-owned Svelte UI is implemented as a separate optional host capability; see the Scene UI demo for the <Game onReady> integration path.

Communicate through the scene bus

type Events = { score: { points: number } };
const score_scene: SceneFactory<Manifest, Events> = ({ events }) => ({
  name: "score",
  enter: () => events.on("score", ({ points }) => console.log(points)),
});

game.scenes.events.emit("score", { points: 10 });