Skip to content

Custom paint ​

Draw your own triangles for a node.

ts
import { Painter, TrianglesPaint } from "willow";

Painter ​

ts
class Painter

The view onto the render pipeline passed to a node's custom-paint function. Only valid while the function runs: using a stored Painter later raises InvalidStateError.

Painter: properties ​

MemberDescription
readonly node: NodeThe node whose custom-paint function is running.

Painter: methods ​

MemberDescription
worldTransform(): Array<float>The node's world transform as six numbers [a, b, c, d, tx, ty]. A point (x, y) maps to (a * x + c * y + tx, b * x + d * y + ty). The camera is applied after painting.
isBuildingCache(): booleanTrue when this paint pass is building a cached subtree (CacheAsTree): skip transient or animated content that should not be folded into the cache.
paintDefault(): voidDraws the node's normal content (sprite, mesh, text, particles) so custom geometry can be added alongside it. Containers draw nothing.
appendTriangles(triangles: TrianglesPaint): voidDraws one batch of triangles. Vertices are copied; the arrays may be reused after.

TrianglesPaint ​

ts
class TrianglesPaint

One batch of textured triangles for Painter.appendTriangles. Vertex positions are in world space: write them through Painter.worldTransform().

TrianglesPaint: constructors ​

ts
new TrianglesPaint(vertices: Float32Array | Array<float>, indices: Array<int>)

Creates a batch from flat vertex data (eight numbers per vertex: x, y, u, v, r, g, b, a, colour channels 0.0 to 1.0) and a triangle list (three vertex indices per triangle).

TrianglesPaint: properties ​

MemberDescription
vertices: Float32Array | Array<float>Flat vertex data, eight numbers per vertex in order: x, y, u, v, r, g, b, a.
indices: Array<int>Triangle list: three vertex indices per triangle.
texture?: Texture | TextureRegionImage sampled by the triangles; omit to draw vertex colours only.
blendMode?: stringBlend mode name such as "normal" or "add" (same names as Node.blendMode).
renderLayer: intRender layer, 0 to 255. Defaults to 0.
globalOrder: intSecondary draw-order key within the render layer. Defaults to 0.