Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
Scene is a lightweight wrapper around a game’s root Node. It holds a factory function that returns (or resolves to) a Node, enabling both synchronous eager initialization and asynchronous lazy loading. The SceneManager tracks all registered scenes and controls which one is currently active.
Scene
Constructor
A function that returns the root
Node for this scene, or a Promise that resolves to one. This function is not called until scene.load() is invoked — keeping asset imports deferred until the scene actually activates.scene.load()
Calls render(), awaits the result, validates that the return value is a Node instance, and returns it. Throws InvalidSceneRootError if the resolved value is not a Node.
load() manually — SceneManager.addScene() (with autoLoad = true) and SceneManager.setScene() call it for you.
Eager scene (no lazy loading)
Pass a plain synchronous function when the scene’s assets are already available. TheNode is constructed immediately when load() is called.
Lazy scene (async import)
Wrap a dynamicimport() inside an async function to defer loading the scene module — and any heavy assets it imports — until the scene is first activated.
Lazy loading is especially valuable for large scenes with many textures or audio files. Only the scenes the player actually visits will ever be loaded, keeping initial startup fast.
SceneManager
SceneManager is available as the singleton Game.sceneManager. It maintains a map of named scenes and exposes methods to register, preload, and switch between them.
See Game for how to access the instance.
sceneManager.addScene(name, scene, autoLoad?)
Registers a scene under a string key. If autoLoad is true, immediately calls setScene(name), loading the scene and making it the active node.
A unique string identifier for the scene. Used with
setScene() and preloadScene() to reference the scene later.The
Scene instance to register.When
true, the method awaits setScene(name) after registering the scene, making it the active scene immediately. Defaults to false.sceneManager.setScene(name | null)
Destroys the current scene’s root node, clears internal state, loads the named scene, and sets it as the active node. Pass null to unload everything without activating a new scene.
The name of the scene to activate, or
null to clear the active scene. Throws SceneNotFoundError if the name has not been registered.sceneManager.preloadScene(name)
Loads the named scene in the background while the current scene keeps running. Returns a setter function; call that function when you want to make the preloaded scene active (e.g., after a transition animation finishes).
The registered name of the scene to preload. Throws
SceneNotFoundError if not found.sceneManager.currentNode
Read-only. Returns the root Node of the currently active scene, or null if no scene is active.
sceneManager.currentScene
Read-only. Returns the string name of the currently active scene, or null if no scene is active.