MotionScript

@motion-script/core


@motion-script/core / LayerStack

Class: LayerStack

Defined in: runtime/globals.ts:129

The ordered stack of project-wide nodes drawn either under or over every scene (ProjectConfig.backgrounds / ProjectConfig.overlays).

A layer is not part of any scene's node tree. Scenes are torn down and rebuilt from their generator on every pass (Scene.reset), so a node parked in one would be disposed the first time that scene replayed and never come back — there is no generator to re-add it. Instead each layer keeps its own viewport frame here, for the whole life of the runtime, and the engine draws the active ones around the scene: backgrounds, scene, overlays.

Living outside the scene also gives layers the semantics the name implies: they are unaffected by the scene camera (zoom/origin/heading), they sit outside the scene's clip, and an overlay covers the scene's own overlay fill rather than being covered by it.

Selection

select resolves which entries apply to the scene about to be drawn; every other method acts on that selection. Both the precomp pass and the playback evaluator call it as they enter a scene, so the two agree on which layers a given scene's frames contain.

Constructors

Constructor

new LayerStack(kind, config, viewport): LayerStack

Defined in: runtime/globals.ts:134

Parameters

kind

LayerKind

config

readonly GlobalLayerConfig[] | undefined

viewport

Size2D

Returns

LayerStack

Accessors

isEmpty

Get Signature

get isEmpty(): boolean

Defined in: runtime/globals.ts:159

True when the project declared no layers of this kind — the common case.

Returns

boolean

Methods

bindAssets()

bindAssets(catalog): void

Defined in: runtime/globals.ts:183

Bind the asset catalog to every active layer's subtree.

Parameters

catalog

AssetCatalog

Returns

void


bindContext()

bindContext(context): void

Defined in: runtime/globals.ts:196

Push inherited context down every active layer.

resolveContext must fire exactly once per node instance, and a layer is never rebuilt, so the run-init flag is tracked per entry rather than taken from the caller: an entry first selected by scene 3 still gets its one init there, and one bound at scene 0 only gets the structural re-push afterwards.

Parameters

context

ContextMap

Returns

void


dispose()

dispose(): void

Defined in: runtime/globals.ts:260

Release the frames this stack built.

A node handed in as a live instance is owned by the project config and outlives the runtime (StrictMode double-mount, HMR), so it is detached before the frame is freed: disposing it would free signals that nothing rebuilds — unlike a scene root, whose children come back from the generator — leaving the next mount with a hollow layer. A factory-built node belongs to this stack and goes down with its frame.

Returns

void


ellapse()

ellapse(totalTime): void

Defined in: runtime/globals.ts:204

Advance every active layer's clock (and its per-frame sampling).

Parameters

totalTime

number

Returns

void


layout()

layout(bounds, scope): void

Defined in: runtime/globals.ts:241

Lay every active layer out against the full viewport.

Parameters

bounds

BoxBounds

scope

MeasureScope

Returns

void


prepareAudioAssets()

prepareAudioAssets(tracker): void

Defined in: runtime/globals.ts:234

Collect audio requests from every active layer (e.g. a Video overlay's own track).

The owner path is prefixed with the layer's kind and index rather than starting at "": paths are how the timeline attributes a waveform to a node in the scene tree, and an unprefixed layer path would land a layer's clip on whichever scene node happened to occupy the same slot. A prefixed path matches nothing, so the clip plays without being drawn on someone else's bar.

Parameters

tracker

AssetTracker

Returns

void


prepareLayoutAssets()

prepareLayoutAssets(): void

Defined in: runtime/globals.ts:214

Fire every active layer's pre-layout async setup.

Returns

void


prepareRenderAssets()

prepareRenderAssets(): void

Defined in: runtime/globals.ts:219

Fire every active layer's pre-render async setup.

Returns

void


render()

render(context): void

Defined in: runtime/globals.ts:246

Draw every active layer, in config order.

Parameters

context

RenderContext

Returns

void


sample()

sample(): void

Defined in: runtime/globals.ts:209

Seed per-frame derived state without a full ellapse (see Node.sample).

Returns

void


select()

select(sceneIndex, sceneName): void

Defined in: runtime/globals.ts:175

Narrow the stack to the layers that apply to a scene. include is an allow-list (absent → every scene); exclude is a deny-list applied after it. Call on entering a scene, before the per-frame methods below.

Parameters

sceneIndex

number

sceneName

string

Returns

void


setViewport()

setViewport(viewport): void

Defined in: runtime/globals.ts:164

Resize every layer frame (the viewport is fixed per run, but set once up front).

Parameters

viewport

Size2D

Returns

void