LayerSet
graphics/layer-set.ts:45An ordered, named set of render layers — the developer-defined draw order a game stamps onto its graphics.
The engine ships no built-in layers. A game declares its own bands once, back-to-front, with defineLayers, and passes the resulting Layer tokens to its graphics components via GraphicsOptions.layer. A Scene created with the set renders each band in order, and within a band keeps insertion (spawn) order — so the cross-band order is stable no matter when objects spawn, while same-band order still falls out of creation order as before.
Type-safe lookup
Like AssetBundle, a LayerSet is just data with compile-checked
keys. Because defineLayers captures the names as their literal types,
LayerSet.get only accepts a name the set actually declares — a typo is
a tsc error, not a runtime ErrorCode.LAYER_NOT_IN_SET that fires
only when the mis-named graphic first spawns.
Construct via defineLayers, not new — the factory captures the
literal name union the constructor's generic alone cannot.
Example
export const layers = defineLayers('ground', 'structures', 'characters', 'ui');
const world = game.createWorld({ layers });
// ground (back) < structures < characters < ui (front)
new Sprite(object, texture, { layer: layers.get('characters') });
layers.get('charcters'); // tsc error: not assignable to the name unionAccessors
Methods
get(name: T[number]): Layer Resolves a layer name to its Layer token. The argument is checked against the set's declared names at compile time.
Parameters
-
nameT[number]
Throws
EngineError with code ErrorCode.LAYER_NOT_IN_SET when the name isn't in the set. With a statically-typed set this is unreachable from well-typed code; it guards dynamic callers.
has(name: string): boolean Whether the set declares a layer with the given name.
Parameters
-
namestring
Returns
boolean