LoadingScene
Defined in: LoadingScene.ts:45
Base class for a progress-bar style loading screen.
Preloads the target scene’s assets through the AssetManager, exposes
progress and emits scene:loading:progress / scene:loading:done on
the engine event bus, enforces minDuration to prevent flicker on cached
loads, then replaces itself with target — optionally through a
transition.
LoadingScene owns orchestration only. It does not render anything. To show
a progress UI, spawn an entity that subscribes to the loading events (the
canonical default is LoadingSceneProgressBar in @yagejs/ui, or any
custom component). The loading scene is a normal Scene, so you can use
onEnter to spawn whatever you want.
class Boot extends LoadingScene { readonly target = new GameScene(); readonly minDuration = 500; readonly transition = fade({ duration: 300 }); override onEnter() { this.spawn(LoadingSceneProgressBar); this.startLoading(); }}
await engine.scenes.replace(new Boot());Set autoContinue = false to gate the handoff behind a continue() call
— useful for “press any key to continue” flows. scene:loading:done
still fires so UI can react (show a prompt), and whoever eventually
calls this.continue() triggers the transition.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LoadingScene():
LoadingScene
Returns
Section titled “Returns”LoadingScene
Inherited from
Section titled “Inherited from”Properties
Section titled “Properties”autoContinue
Section titled “autoContinue”
readonlyautoContinue:boolean=true
Defined in: LoadingScene.ts:70
When true (default), the handoff fires automatically after loading and
minDuration. Set false to gate it behind continue() — useful when
the loading scene also asks the player to press a key or click.
defaultTransition?
Section titled “defaultTransition?”
readonlyoptionaldefaultTransition?:SceneTransition
Defined in: Scene.ts:101
Default transition used when this scene is the destination of a push/pop/replace.
Inherited from
Section titled “Inherited from”minDuration
Section titled “minDuration”
readonlyminDuration:number=0
Defined in: LoadingScene.ts:60
Minimum wall-clock ms the scene stays visible before handing off. Prevents flicker on cached loads. Default 0.
readonlyname:string="loading"
Defined in: LoadingScene.ts:46
Name for debugging/inspection.
Overrides
Section titled “Overrides”pauseBelow
Section titled “pauseBelow”
readonlypauseBelow:boolean=true
Defined in: Scene.ts:79
Whether scenes below this one in the stack should be paused. Default: true.
Inherited from
Section titled “Inherited from”paused
Section titled “paused”paused:
boolean=false
Defined in: Scene.ts:104
Manual pause flag. Set by game code to pause this scene regardless of stack position.
Inherited from
Section titled “Inherited from”preload?
Section titled “preload?”
readonlyoptionalpreload?: readonlyAssetHandle<unknown>[]
Defined in: Scene.ts:98
Asset handles to load before onEnter(). Override in subclasses.
Inherited from
Section titled “Inherited from”target
Section titled “target”Defined in: LoadingScene.ts:54
Scene to load and transition to. Accepts an instance or a factory —
use a factory when target construction should be deferred until
loading starts (heavy constructors, side effects). The factory runs
before assets.loadAll so target.preload can be inspected.
timeScale
Section titled “timeScale”timeScale:
number=1
Defined in: Scene.ts:107
Time scale multiplier for this scene. 1.0 = normal, 0.5 = half speed. Default: 1.
Inherited from
Section titled “Inherited from”transition?
Section titled “transition?”
readonlyoptionaltransition?:SceneTransition
Defined in: LoadingScene.ts:63
Transition used for the loading → target handoff.
transparentBelow
Section titled “transparentBelow”
readonlytransparentBelow:boolean=false
Defined in: Scene.ts:95
Whether scenes below this one should still render. Default: false.
When false (the default), the renderer hides every below-stack scene
tree — both world-space layers AND screen-space layers (HUD, UI panels,
dialogs). Set true for pause menus, dialog overlays, or any scene
that should be drawn on top of a still-visible game world.
The chain composes: a below scene stays visible only while every scene
above it has transparentBelow = true. While a scene transition is
running, both the outgoing and incoming scenes render regardless of
this flag so transitions like crossFade keep working; the chain is
reapplied when the transition ends.
Inherited from
Section titled “Inherited from”Accessors
Section titled “Accessors”assets
Section titled “assets”Get Signature
Section titled “Get Signature”get assets():
AssetManager
Defined in: Scene.ts:151
Convenience accessor for the AssetManager.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”context
Section titled “context”Get Signature
Section titled “Get Signature”get context():
EngineContext
Defined in: Scene.ts:126
Access the EngineContext.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”isPaused
Section titled “isPaused”Get Signature
Section titled “Get Signature”get isPaused():
boolean
Defined in: Scene.ts:131
Whether this scene is effectively paused (manual pause or paused by stack).
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isTransitioning
Section titled “isTransitioning”Get Signature
Section titled “Get Signature”get isTransitioning():
boolean
Defined in: Scene.ts:145
Whether a scene transition is currently running.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”progress
Section titled “progress”Get Signature
Section titled “Get Signature”get progress():
number
Defined in: LoadingScene.ts:102
Current load progress, 0 → 1. Updated as the AssetManager reports progress.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”_addExistingEntity()
Section titled “_addExistingEntity()”_addExistingEntity(
entity):void
Defined in: Scene.ts:348
Internal
Add an existing entity to this scene (used by Entity.addChild for auto-scene-membership).
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_clearScopedServices()
Section titled “_clearScopedServices()”_clearScopedServices():
void
Defined in: Scene.ts:539
Internal
Clear all scene-scoped services. Called by the SceneManager after
afterExit hooks run, so plugin cleanup code still sees scoped state.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_destroyAllEntities()
Section titled “_destroyAllEntities()”_destroyAllEntities():
void
Defined in: Scene.ts:602
Internal
Destroy all entities — used during scene exit. Clears the identity
index in bulk; per-entity key removal in _flushDestroyQueue is the
in-game path.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_flushDestroyQueue()
Section titled “_flushDestroyQueue()”_flushDestroyQueue():
void
Defined in: Scene.ts:576
Internal
Flush the destroy queue — destroy pending entities. Called by the engine during the endOfFrame phase.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_observeEntityEvent()
Section titled “_observeEntityEvent()”_observeEntityEvent(
eventName,data,entity):void
Defined in: Scene.ts:464
Internal
Observe entity-scoped event emissions after they dispatch locally and
bubble to the scene. Tooling only; game code should keep using on().
Parameters
Section titled “Parameters”eventName
Section titled “eventName”string
unknown
entity
Section titled “entity”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_onEntityEvent()
Section titled “_onEntityEvent()”_onEntityEvent(
eventName,data,entity):void
Defined in: Scene.ts:450
Internal
Called by Entity.emit() for bubbling entity events to the scene.
Parameters
Section titled “Parameters”eventName
Section titled “eventName”string
unknown
entity
Section titled “entity”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_queueDestroy()
Section titled “_queueDestroy()”_queueDestroy(
entity):void
Defined in: Scene.ts:368
Internal
Add an entity to the destroy queue. Called by Entity.destroy().
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_registerKey()
Section titled “_registerKey()”_registerKey(
entity,key):void
Defined in: Scene.ts:331
Internal
Internal: register a key on a freshly spawned entity. Throws on
duplicate so callers (Scene.spawn) can abort before adding to
this.entities or emitting entity:created.
Parameters
Section titled “Parameters”entity
Section titled “entity”string
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_registerScoped()
Section titled “_registerScoped()”_registerScoped<
T>(key,value):void
Defined in: Scene.ts:512
Internal
Internal alias for registerScoped kept so existing plugin/test code
doesn’t churn. Prefer registerScoped in new code.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
T
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_resolveScoped()
Section titled “_resolveScoped()”_resolveScoped<
T>(key):T|undefined
Defined in: Scene.ts:530
Internal
Resolve a scene-scoped service, or undefined if none was registered.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
Returns
Section titled “Returns”T | undefined
Inherited from
Section titled “Inherited from”_setContext()
Section titled “_setContext()”_setContext(
context):void
Defined in: Scene.ts:547
Internal
Set the engine context. Called by SceneManager when the scene is pushed.
Parameters
Section titled “Parameters”context
Section titled “context”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_setEntityEventObserver()
Section titled “_setEntityEventObserver()”_setEntityEventObserver(
observer?):void
Defined in: Scene.ts:520
Internal
Install or clear a tooling-only observer for bubbled entity events.
Parameters
Section titled “Parameters”observer?
Section titled “observer?”(eventName, data, entity) => void
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”afterRestore()?
Section titled “afterRestore()?”
optionalafterRestore(data,resolve):void
Defined in: Scene.ts:489
Called after entities are restored during save/load. Rebuild non-serializable state here.
Parameters
Section titled “Parameters”unknown
resolve
Section titled “resolve”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”continue()
Section titled “continue()”continue():
void
Defined in: LoadingScene.ts:148
Trigger the handoff to target. No-op if already called or if
autoContinue already fired it. If called before loading finishes,
the handoff runs as soon as loading + minDuration complete.
Returns
Section titled “Returns”void
destroyEntity()
Section titled “destroyEntity()”destroyEntity(
entity):void
Defined in: Scene.ts:360
Mark an entity for destruction. Deferred to endOfFrame flush.
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”emit()
Section titled “emit()”Call Signature
Section titled “Call Signature”emit(
token):void
Defined in: Scene.ts:435
Emit a typed event at the scene level. Scene-level on handlers fire
with entity = undefined to indicate there’s no emitting entity.
Symmetric to Entity.emit but for scene-scoped signalling.
Parameters
Section titled “Parameters”EventToken<void>
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”emit<
T>(token,data):void
Defined in: Scene.ts:436
Emit a typed event at the scene level. Scene-level on handlers fire
with entity = undefined to indicate there’s no emitting entity.
Symmetric to Entity.emit but for scene-scoped signalling.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”EventToken<T>
T
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”findByKey()
Section titled “findByKey()”findByKey<
E>(key):E|undefined
Defined in: Scene.ts:319
Look up an entity by its stable identity key, scoped to this scene.
Returns undefined for unknown or already-destroyed entities.
Type Parameters
Section titled “Type Parameters”Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”E | undefined
Inherited from
Section titled “Inherited from”findEntities()
Section titled “findEntities()”Call Signature
Section titled “Call Signature”findEntities<
T>(filter):Entity&T[]
Defined in: Scene.ts:395
Find entities matching a filter. Trait filter narrows the return type.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”filter
Section titled “filter”EntityFilter & object
Returns
Section titled “Returns”Entity & T[]
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”findEntities(
filter?):Entity[]
Defined in: Scene.ts:396
Find entities matching a filter. Trait filter narrows the return type.
Parameters
Section titled “Parameters”filter?
Section titled “filter?”Returns
Section titled “Returns”Entity[]
Inherited from
Section titled “Inherited from”findEntitiesByTag()
Section titled “findEntitiesByTag()”findEntitiesByTag(
tag):Entity[]
Defined in: Scene.ts:386
Find entities by tag.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Entity[]
Inherited from
Section titled “Inherited from”findEntity()
Section titled “findEntity()”findEntity(
name):Entity|undefined
Defined in: Scene.ts:378
Find entity by name (first match).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Entity | undefined
Inherited from
Section titled “Inherited from”getEntities()
Section titled “getEntities()”getEntities():
ReadonlySet<Entity>
Defined in: Scene.ts:373
Get all active entities.
Returns
Section titled “Returns”ReadonlySet<Entity>
Inherited from
Section titled “Inherited from”on<
T>(token,handler): () =>void
Defined in: Scene.ts:413
Subscribe to scene-level events. Handlers fire for both:
- bubbled events from any entity (via
entity.emit) —entityis the source - scene-emitted events (via
scene.emit) —entityisundefined
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”EventToken<T>
handler
Section titled “handler”(data, entity?) => void
Returns
Section titled “Returns”() => void
Inherited from
Section titled “Inherited from”onEnter()?
Section titled “onEnter()?”
optionalonEnter():void
Defined in: Scene.ts:474
Called when the scene is entered (after preload completes).
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”onExit()
Section titled “onExit()”onExit():
void
Defined in: LoadingScene.ts:154
Called when the scene is exited (popped or replaced).
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”onLoadError()?
Section titled “onLoadError()?”
optionalonLoadError(error):void|Promise<void>
Defined in: LoadingScene.ts:85
Optional hook; fires if asset loading rejects. The scene stays mounted
whether or not this is set. When set, the hook is the recovery channel:
draw a retry UI, push an error scene, or call this.startLoading()
again to retry the load. When unset, the error is logged via the engine
logger and the scene remains mounted in a failed state with no
automatic recovery.
The hook may still be running when the scene is replaced externally —
don’t assume the scene is live (check this.context.tryResolve rather
than this.service before touching engine services, and avoid spawning
new entities after an await).
Parameters
Section titled “Parameters”Error
Returns
Section titled “Returns”void | Promise<void>
onPause()?
Section titled “onPause()?”
optionalonPause():void
Defined in: Scene.ts:480
Called when a scene is pushed on top of this one.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”onProgress()?
Section titled “onProgress()?”
optionalonProgress(ratio):void
Defined in: Scene.ts:471
Called during asset preloading with progress ratio (0→1).
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”onResume()?
Section titled “onResume()?”
optionalonResume():void
Defined in: Scene.ts:483
Called when the scene above is popped, restoring this scene.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”registerScoped()
Section titled “registerScoped()”registerScoped<
T>(key,value):void
Defined in: Scene.ts:502
Register a scene-scoped service. Plugins call this from their
beforeEnter hook to expose per-scene state (render tree, physics
world, …) resolvable via Component.use(key). Game code can also use
it to attach scene-local services without needing a plugin.
Auto-cleared on scene exit — every key registered here is unregistered
after onExit runs (and after plugin afterExit hooks see them).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
T
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”serialize()?
Section titled “serialize()?”
optionalserialize():unknown
Defined in: Scene.ts:486
Return a JSON-serializable snapshot of this scene’s custom state. Used by the save system.
Returns
Section titled “Returns”unknown
Inherited from
Section titled “Inherited from”service()
Section titled “service()”
protectedservice<T>(key):T
Defined in: Scene.ts:162
Lazy proxy-based service resolution. Can be used at field-declaration time:
readonly layers = this.service(RenderLayerManagerKey);The actual resolution is deferred until first property access.
Type Parameters
Section titled “Type Parameters”T extends object
Parameters
Section titled “Parameters”ServiceKey<T>
Returns
Section titled “Returns”T
Inherited from
Section titled “Inherited from”spawn()
Section titled “spawn()”Call Signature
Section titled “Call Signature”spawn(
name?,options?):Entity
Defined in: Scene.ts:198
Spawn a new entity in this scene.
Pass { key } in the trailing options to register a stable per-scene
identity key, looked up later via scene.findByKey. The key is assigned
before setup() runs, so entity.requireKey() is safe inside it.
Runtime routing for the 2-arg class form (spawn(Class, X)):
- If the class doesn’t declare
setup→Xis options. - Else if
X’s own keys are exactly SpawnOptions fields ({ key }) →Xis options. Covers bothsetup(params = {})keyed without params andsetup()(no real params) keyed. - Else →
Xis params (forwarded tosetup). The 3-arg form is always unambiguous:spawn(Class, params, options).
Don’t name a top-level setup-params field key — the shape check would
misroute it. If you must, use the 3-arg form.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”spawn<
P>(blueprint,params,options?):Entity
Defined in: Scene.ts:205
Spawn from a blueprint. Note: blueprint params must not include a
top-level key: string field — the runtime can’t disambiguate it from
SpawnOptions. If your params do, use the explicit 3-arg form
(spawn(bp, params, { key })) so options arrives in the trailing slot.
Type Parameters
Section titled “Type Parameters”P
Parameters
Section titled “Parameters”blueprint
Section titled “blueprint”Blueprint<P>
params
Section titled “params”P
options?
Section titled “options?”Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”spawn(
blueprint,options?):Entity
Defined in: Scene.ts:206
Spawn a new entity in this scene.
Pass { key } in the trailing options to register a stable per-scene
identity key, looked up later via scene.findByKey. The key is assigned
before setup() runs, so entity.requireKey() is safe inside it.
Runtime routing for the 2-arg class form (spawn(Class, X)):
- If the class doesn’t declare
setup→Xis options. - Else if
X’s own keys are exactly SpawnOptions fields ({ key }) →Xis options. Covers bothsetup(params = {})keyed without params andsetup()(no real params) keyed. - Else →
Xis params (forwarded tosetup). The 3-arg form is always unambiguous:spawn(Class, params, options).
Don’t name a top-level setup-params field key — the shape check would
misroute it. If you must, use the 3-arg form.
Parameters
Section titled “Parameters”blueprint
Section titled “blueprint”Blueprint<void>
options?
Section titled “options?”Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”spawn<
E,P>(Class,params,options?):E
Defined in: Scene.ts:208
Spawn an entity subclass with setup params.
Type Parameters
Section titled “Type Parameters”E extends Entity
P
Parameters
Section titled “Parameters”() => E & object
params
Section titled “params”P
options?
Section titled “options?”Returns
Section titled “Returns”E
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”spawn<
E>(Class,options?):E
Defined in: Scene.ts:214
Spawn an entity subclass without setup params.
Type Parameters
Section titled “Type Parameters”E extends Entity
Parameters
Section titled “Parameters”() => E
options?
Section titled “options?”Returns
Section titled “Returns”E
Inherited from
Section titled “Inherited from”startLoading()
Section titled “startLoading()”startLoading():
void
Defined in: LoadingScene.ts:123
Kick off asset loading. While a load is in flight, subsequent calls
are no-ops. After a load failure the guard is released, so calling
startLoading() from onLoadError (or from a retry button) kicks off
a fresh load against the same target.
Usually called once from onEnter after spawning the loading UI:
override onEnter() { this.spawn(LoadingSceneProgressBar); this.startLoading();}Deferring the call lets you gate the start of the load behind a title screen, “press any key” prompt, intro animation, etc.
Returns
Section titled “Returns”void