SceneConfig and BaseScene01 / 13

Scenes and SceneManager

A scene sets up its environment and delegates game behavior to other objects.

SceneConfig describes the scene’s key, class, assets, layout, and FSM. Block Puzzle defines its game scene in this configuration. scene.config.ts

import { GameScene } from '../../GameScene';

import { GameFsm } from './fsm.config';

import type { SceneConfig } from '@gamedevland/engine/core';

export class GameSceneDefinition {
  static readonly config: SceneConfig = {
    key: 'game',
    useClass: GameScene,
    layout: 'json/layouts/scenes/game/layout.json',
    fsm: GameFsm.config,
  };
}

BaseScene provides a shared lifecycle. FsmDrivenScene adds ready and update events so the FSM can manage the game flow.

01
preload()Loads assets from SceneConfig.assets.
02
onEnter()
  1. Creates the scene DI container and builds the layout
  2. Prepares the configurations and starts services
  3. Activates components and starts the FSM if configured
  4. Calls create(). In FsmDrivenScene, this method sends SceneReady.
03
onExit()Stops the FSM and releases scene services, particles, layout, and DI.

In the public project, GameScene simply passes the configuration to its base class. Piece placement logic lives elsewhere.

Scene transitions

SceneManager.start(key) opens the initial scene. replace(key, options) replaces the top scene, push adds a scene to the stack, and pop removes the top one. Only the top scene updates, and only while it is unpaused. Transitions run through a queue, and lifecycle hooks have a timeout.

Pass input to the new scene through options.params. A command reads it from sceneParams and validates it with decodeSceneParams. Transition parameters are separate from the current session state.

Sources ↗

Block Puzzle · scene.config.ts↗Game scene configuration.