Renderer
Draws every entity with Position + Sprite, and loads textures and fonts: game.get(Renderer).
Properties
Section titled “Properties”additive
Section titled “additive”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).
backend
Section titled “backend”
readonlybackend:"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
Section titled “screen”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).
readonlystats:object
Last frame’s totals, for profiling (devtools() shows them).
drawCalls
Section titled “drawCalls”drawCalls:
number
sprites
Section titled “sprites”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.
Methods
Section titled “Methods”burst()
Section titled “burst()”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.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”void
createTexture()
Section titled “createTexture()”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() })
Parameters
Section titled “Parameters”number
height
Section titled “height”number
(ctx) => void
options?
Section titled “options?”Returns
Section titled “Returns”number
loadAtlas()
Section titled “loadAtlas()”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].
Parameters
Section titled “Parameters”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<Atlas>
loadFont()
Section titled “loadFont()”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.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Promise<Font>
loadTexture()
Section titled “loadTexture()”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.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<number>
loadTextures()
Section titled “loadTextures()”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.
Type Parameters
Section titled “Type Parameters”M extends Record<string, TextureSource>
Parameters
Section titled “Parameters”manifest
Section titled “manifest”M
Returns
Section titled “Returns”Promise<{ [K in string | number | symbol]: number }>
