Skip to content

registerTexture

registerTexture(key, texture): void

Defined in: renderer/src/assets.ts:542

Register a runtime-created texture under an asset key, so every key-based surface resolves it exactly like a preloaded asset: texture: key on SpriteComponent and on a particle emitter, and { sheet: key, frameWidth } on a FrameSource.

Registered keys are engine-global and live until unregisterTexture — registration is a boot-scoped act, outside the asset manager’s ref counts and unloads. A game-owned save root can store the key, but the game must re-register runtime textures under the same keys during boot before it reconstructs scenes and components. Resolving a missing key throws and names the key.

Re-registering a key this API still owns replaces the cache entry; components constructed before the replacement keep the old texture instance (resolution happens at construction). A key present in the cache but owned by the asset pipeline — a loaded asset’s path, or an asset that overwrote a stale registration — throws: shadowing a loaded asset would let that asset’s unload destroy the registered texture later.

// The size names the strip's region, so every 32-pixel cell holds one circle.
const strip = renderer.createTexture(
(g) => {
for (let i = 0; i < 4; i++) g.circle(i * 32 + 16, 16, 4 + i * 3).fill(0xffcc00);
},
{ width: 128, height: 32 },
);
registerTexture("boss-idle", strip);
entity.add(new AnimatedSpriteComponent({ source: { sheet: "boss-idle", frameWidth: 32 } }));

string

TextureResource

void

Coding agents: fetch https://yage.dev/llms.txt first and prefer the Markdown references it links over these HTML pages. This page's Markdown counterpart is /llms/packages/renderer.md.