Skip to content

Polygon and Mesh ​

Filled shapes and raw triangle meshes.

ts
import { Polygon, Mesh } from "willow";

Polygon ​

ts
class Polygon extends Node

Extends Node.

Filled polygon backed by one vertex-coloured mesh.

Polygon: constructors ​

ts
new Polygon(points: Float32Array | Array<float>, color: Color)

points is a flat [x0, y0, x1, y1...] array (at least 3 points).

Polygon: properties ​

MemberDescription
readonly color: ColorSolid fill colour (0xRRGGBBAA, always 8 digits, a 6-digit literal is read as A=0x00, fully transparent).

Polygon: methods ​

MemberDescription
setPoints(points: Float32Array | Array<float>, color?: Color): voidReplaces this polygon's vertices and, optionally, its colour. Same point/colour shape as the constructor.
setColor(color: Color): voidEquivalent to polygon.color = color. Solid fill colour.

Polygon: static methods ​

MemberDescription
static regular(sides: int, radius: float, color: Color): PolygonCreates a solid-colour regular polygon with sides vertices centred at the polygon origin.
static star(points: int, outerRadius: float, innerRadius: float, color: Color): PolygonCreates a solid-colour star polygon with points outer points, alternating outerRadius/innerRadius.
static circle(radius: float, color: Color): PolygonCreates a solid-colour circle, approximated as a 32-segment regular polygon, Equivalent to Polygon.regular(32, radius, color).
static triangle(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: Color): PolygonCreates a solid-colour triangle from three arbitrary points. A thin wrapper over the general Polygon(points, color) constructor for exactly 3 points.
static textured(texture: Texture | TextureRegion, points: Float32Array | Array<float>): PolygonCreates a textured polygon mesh. Points form an arbitrary simple polygon triangulated via ear-clipping; texture coordinates are normalized from the polygon bounding box to the texture region.

Mesh ​

ts
class Mesh extends Node

Extends Node.

Untextured mesh. Vertices use x, y, u, v, r, g, b, a stride order.

Mesh: constructors ​

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

vertices uses x, y, u, v, r, g, b, a stride order; indices are triangle-list vertex indices.

Mesh: properties ​

MemberDescription
tint: ColorColour tint, a Color, default Color.WHITE. It multiplies the vertex colours at draw time, so a colour change does not rebuild the vertex buffer.

Mesh: methods ​

MemberDescription
setVertices(vertices: Float32Array | Array<float>): voidReplaces this mesh's vertex buffer. Same x, y, u, v, r, g, b, a stride order as the constructor.
setIndices(indices: Uint16Array | Array<int>): voidReplaces this mesh's triangle-list index buffer.
invalidateBounds(): voidForces this mesh's cached bounds to be recomputed on next use, after an out-of-band vertex edit.