Skip to content

LayeredAnimationController

Defined in: packages/renderer/src/LayeredAnimationController.ts:44

Fan-out wrapper around N sibling AnimationController instances.

Use this when a single logical character is composed of multiple sprite layers (head + body + outfit) — each layer has its own AnimatedSpriteComponent + AnimationController, but they all need to play("walk") or playOneShot("attack") in unison.

  • play(name) is forwarded to every child controller.
  • playOneShot(name, opts) computes a single shared duration from the first child (or opts.duration) and passes it to every child as options.duration — so all layers unlock on the same frame regardless of per-layer frame counts.
  • The wrapper owns the master lock timer and fires the user’s onComplete exactly once.
class Hero extends Entity {
setup() {
this.add(new Transform());
const body = this.spawnChild("body", HeroLayer, { sheet: "body.png" });
const head = this.spawnChild("head", HeroLayer, { sheet: "head.png" });
this.add(new LayeredAnimationController({
controllers: [body.get(AnimationController), head.get(AnimationController)],
}));
}
}
  • Component

T extends string = string

new LayeredAnimationController<T>(options): LayeredAnimationController<T>

Defined in: packages/renderer/src/LayeredAnimationController.ts:54

LayeredAnimationControllerOptions<T>

LayeredAnimationController<T>

Component.constructor

enabled: boolean

Defined in: packages/core/dist/index.d.ts:1872

Whether this component is active. Disabled components are skipped by ComponentUpdateSystem.

Component.enabled


entity: Entity

Defined in: packages/core/dist/index.d.ts:1870

Back-reference to the owning entity. Set by the engine when the component is added to an entity. Do not set manually.

Component.entity

get context(): EngineContext

Defined in: packages/core/dist/index.d.ts:1885

Access the EngineContext from the entity’s scene. Throws if the entity is not in a scene.

EngineContext

Component.context


get controllers(): readonly AnimationController<T>[]

Defined in: packages/renderer/src/LayeredAnimationController.ts:65

Sibling controllers being driven.

readonly AnimationController<T>[]


get current(): "" | T

Defined in: packages/renderer/src/LayeredAnimationController.ts:70

Currently playing animation name, or "" if none.

"" | T


get locked(): boolean

Defined in: packages/renderer/src/LayeredAnimationController.ts:75

True if a one-shot animation is blocking.

boolean


get scene(): Scene

Defined in: packages/core/dist/index.d.ts:1880

Access the entity’s scene. Throws if the entity is not in a scene. Prefer this over threading through this.entity.scene in component code.

Scene

Component.scene

_runCleanups(): void

Defined in: packages/core/dist/index.d.ts:1926

Internal

Run and clear all registered cleanups. Called by Entity.remove() and Entity._performDestroy() before onRemove/onDestroy.

void

Component._runCleanups


protected addCleanup(fn): void

Defined in: packages/core/dist/index.d.ts:1920

Register a cleanup function to run when this component is removed or destroyed.

() => void

void

Component.addCleanup


optional afterRestore(data, resolve): void

Defined in: packages/core/dist/index.d.ts:1940

Called after onAdd() during save/load restoration. Apply state that depends on onAdd() having run.

unknown

SnapshotResolver

void

Component.afterRestore


optional fixedUpdate(dt): void

Defined in: packages/core/dist/index.d.ts:1936

Called every fixed timestep by the built-in ComponentUpdateSystem.

number

void

Component.fixedUpdate


forcePlay(name): void

Defined in: packages/renderer/src/LayeredAnimationController.ts:117

Clear the lock and force-switch every layer to the given animation.

T

void


protected listen<T>(entity, token, handler): void

Defined in: packages/core/dist/index.d.ts:1912

Subscribe to events on any entity, auto-unsubscribe on removal.

T

Entity

EventToken<T>

(data) => void

void

Component.listen


protected listenScene<T>(token, handler): void

Defined in: packages/core/dist/index.d.ts:1918

Subscribe to scene-level events, auto-unsubscribe on removal. Handlers fire for bubbled entity events (entity = source) and scene.emit events (entity = undefined).

T

EventToken<T>

(data, entity?) => void

void

Component.listenScene


optional onAdd(): void

Defined in: packages/core/dist/index.d.ts:1928

Called when the component is added to an entity.

void

Component.onAdd


optional onDestroy(): void

Defined in: packages/core/dist/index.d.ts:1932

Called when the component is destroyed (entity destroyed or component removed).

void

Component.onDestroy


optional onRemove(): void

Defined in: packages/core/dist/index.d.ts:1930

Called when the component is removed from an entity.

void

Component.onRemove


play(name): void

Defined in: packages/renderer/src/LayeredAnimationController.ts:80

Play a named animation on every layer. No-op if already current or locked.

T

void


playOneShot(name, options?): void

Defined in: packages/renderer/src/LayeredAnimationController.ts:97

Play a one-shot on every layer with a shared lock duration.

If options.duration is omitted, the duration is computed once from the first controller via AnimationController.calcDuration and stored on this wrapper as the single source of truth. Children are given an Infinity per-controller duration so their own lock timers never expire independently — clearing them happens through this wrapper’s unlock when the master timer fires. This avoids a race where a child’s update() could tick out a frame before the wrapper’s (e.g. if components are ordered differently in the scheduler, or accumulated float drift makes one timer cross the threshold a frame earlier).

T

number

() => void

void


serialize(): null

Defined in: packages/renderer/src/LayeredAnimationController.ts:147

Return a JSON-serializable snapshot of this component’s state. Used by the save system.

null

Component.serialize


protected service<T>(key): T

Defined in: packages/core/dist/index.d.ts:1902

Lazy proxy-based service resolution. Can be used at field-declaration time:

readonly input = this.service(InputManagerKey);

The actual resolution is deferred until first property access.

T extends object

ServiceKey<T>

T

Component.service


protected sibling<C>(cls): C

Defined in: packages/core/dist/index.d.ts:1910

Lazy proxy-based sibling component resolution. Can be used at field-declaration time:

readonly anim = this.sibling(AnimatedSpriteComponent);

The actual resolution is deferred until first property access.

C extends Component

ComponentClass<C>

C

Component.sibling


unlock(): void

Defined in: packages/renderer/src/LayeredAnimationController.ts:124

Manually release the one-shot lock on this wrapper and every child.

void


update(dt): void

Defined in: packages/renderer/src/LayeredAnimationController.ts:133

Tick the shared one-shot lock timer.

number

void

Component.update


protected use<T>(key): T

Defined in: packages/core/dist/index.d.ts:1893

Resolve a service by key, cached after first lookup. Scene-scoped values (registered via scene._registerScoped) take precedence over engine scope. A key declared with scope: "scene" that falls back to engine scope emits a one-shot dev warning — almost always signals a missed beforeEnter hook.

T

ServiceKey<T>

T

Component.use