Skip to content

registerTexture

registerTexture(key, texture): void

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

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, { sheet: key, frameWidth } on a FrameSource, and textureKey: key on particle emitters.

Registered keys are engine-global and live until unregisterTexture — registration is a boot-scoped act, outside the asset manager’s ref counts and unloads. Snapshots store only the key, so for save/load the game re-registers its runtime textures under the same keys before restoring (the same boot code that registered them on first run); resolving a missing key throws, naming 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.

const strip = renderer.createTexture((g) => {
for (let i = 0; i < 4; i++) g.circle(i * 32 + 16, 16, 4 + i * 3).fill(0xffcc00);
});
registerTexture("boss-idle", strip);
entity.add(new AnimatedSpriteComponent({ source: { sheet: "boss-idle", frameWidth: 32 } }));

string

TextureResource

void