Skip to main content

Scene Manager

Spinorium provides a simple SceneManager to switch between scenes. It keeps the active scene on the stage, disposes the previous one, and handles layout updates. Custom game scenes could extend the Scene base class, while layout scenes exported from the editor extend EditorScene and accept a resource alias in the constructor.

The PlayerController by default handles transitions between two scenes: splash screen and main game. You only need to specify the scene aliases in the template configuration.

export class GameController extends PlayerController {
protected override createTemplateConfig():TemplateConfig {
return ConfigUtil.overrideConfig(super.createTemplateConfig(), {
splashSceneType: 'splashScene',
mainSceneType: 'mainScene'
});
}
}

Switching Between Scenes

The SceneManager class provides the following methods:

  • createScene(sceneType, withCache?) – Creates a scene instance from a class, existing instance, or editor alias. When caching is enabled the instance is reused across transitions.
  • changeScene(sceneType, params?, withCache?) – Disposes the current scene, composes the new one, and adds it to the stage. Optional parameters are forwarded to Scene.compose.
  • updateLayout() – Re-applies responsive layouts on the active scene, typically after viewport changes.

Scene Lifecycle

The Scene class defines the lifecycle hooks that wrap each transition:

  • compose(params?) – Called every time the scene becomes active. Parameters from changeScene are stored on the scene so they stay available during the session.
  • updateLayout() – Invoked right after composition and on every viewport resize triggered by the engine. Use it to reposition display objects with System.viewport information or device checks.
  • dispose() – Runs before the scene leaves the stage. Clean up listeners, timelines, and cached references here before delegating to super.dispose().

Accessing Scene Children

The Scene class exposes utilities for finding display objects inside the scene tree:

  • obtainChildByPath(path, forceCache?) – Searches by slash-delimited name, caches the result by default, and returns null when the path is invalid.

It's recommended to use System.scenes.obtainChildByPath method that proxies to the active scene so runtime code can reach elements without storing references.

Accessing Scene Children Example

const character = System.scenes.obtainChildByPath<SpineAnimation>('bg/character/animation');

if (character != null) {
character.play('walk');
}