Skip to content

Renderer

Draws every entity with Position + Sprite, and loads textures and fonts: game.get(Renderer).

additive: Set<number>

z layers drawn with additive blending: colors add up and never darken, for glows, fire, magic and sparks (particles of the layer too). Black adds nothing, so additive art works best on a dark background. renderer.additive.add(5).


readonly backend: "webgl2" | "webgpu"

The GPU API in use; webgpu() falls back to webgl2 where WebGPU is not available.


clip: Map<number, Clip>

Clips z layers to a rectangle in screen pixels ((0, 0) is the top-left corner): scrolling lists, minimaps, windows. renderer.clip.set(100, { x: 20, y: 80, w: 300, h: 200 }); renderer.clip.delete(100) removes it.


screen: Set<number>

z layers drawn in screen pixels, ignoring the camera: HUD, score, menus. (0, 0) is the top-left corner. renderer.screen.add(100).


readonly stats: object

Last frame’s totals, for profiling (devtools() shows them).

drawCalls: number

sprites: number


ySort: Set<number>

z layers drawn in order of each sprite’s bottom edge (y + h / 2, or wherever Anchor puts it) instead of batched by texture, so things lower on screen cover things behind them (2.5D, isometric). Ties keep spawn order. renderer.ySort.add(1). Sprites in a sorted layer that share one texture still draw in a single call.

burst(options): void

Fires a burst of particles: sparks, dust, pickups. They live on the GPU (the vertex shader moves and fades them), so a burst costs one small upload and nothing per frame after that, however many are flying.

BurstOptions

void


createTexture(width, height, draw, options?): number

Makes a texture by drawing on a width x height Canvas 2D: polygons, gradients, rounded panels, anything the canvas API draws. It is drawn once; spawn sprites with the returned id as often as you like. renderer.createTexture(64, 64, (ctx) => { ctx.fillStyle = '#fff'; ctx.beginPath(); ... ctx.fill() })

number

number

(ctx) => void

TextureOptions

number


loadAtlas(url, options?): Promise<Atlas>

Loads a packed spritesheet: the JSON that Aseprite or TexturePacker export, and its image. Frames can have any size and be trimmed; tags become ready-made animations. Cached by URL. const hero = await renderer.loadAtlas(heroJson), then [Sprite, hero.sprite('idle 0')] and [Animation, hero.tags.run].

string

AtlasOptions

Promise<Atlas>


loadFont(options?): Promise<Font>

Renders a font (a CSS family, including web fonts) into a texture for spawnText: ASCII, accented Latin letters, ñ, ¿, ¡ and Nahuatl macron vowels, plus chars. Glyphs are white so tint colors them. Cached by options.

FontOptions

Promise<Font>


loadTexture(url, options?): Promise<number>

Loads an image and returns its texture id, to be stored in Sprite.texture. Cached by URL and options, so restarting a scene reuses it.

string

TextureOptions

Promise<number>


loadTextures<M>(manifest): Promise<{ [K in string | number | symbol]: number }>

Loads several textures in parallel: const t = await loadTextures({ box: boxUrl }) gives a typed t.box.

M extends Record<string, TextureSource>

M

Promise<{ [K in string | number | symbol]: number }>