Scenes & SceneManager
A real game is not one giant messy screen—it has a Title Menu, a Town, Dungeons, and a Game Over screen. Scenes keep each screen cleanly separated like rooms in a house.
Without Scenes
Putting menu buttons, town NPCs, and dungeon monsters into one giant array means every screen change requires manually deleting dozens of objects and hoping nothing leaks into the next level.
Why Maverick Built SceneManager
Each Scene owns its own Elements list. Switching scenes automatically calls onExit() on the old room and onEnter() on the new room.
1. Creating & Switching Scenes
Subclass Scene to run setup/cleanup logic when the player enters or leaves a room, then register them on this.Scenes.
import { Game, Scene } from 'maverick';
class TitleScene extends Scene {
onEnter(game: Game): void { game.Logger.info('Entered Title'); }
onExit(game: Game): void { game.Logger.info('Left Title'); }
}
class MyGame extends Game {
onReady(): void {
this.Scenes.add(new TitleScene(this.Logger, { id: 'title' }));
this.Scenes.add(new Scene(this.Logger, { id: 'town', depthSort: true }));
this.Scenes.switchTo('title', this);
}
onDisengaged(): void {}
}
PoC — Switching Isolated Scenes (
title ↔ town)Active scene: title