The pack
pathNotation
function pathNotation(): Pack<{ pathNotation: PathNotationApi }>
The path-notation pack: routes authored as chained segments in plain data, baked for even speed. Pure maths.
Classes
Path
class Path
A 2D path: curve segments chained into one constant-speed route, baked once.
const swoop = new Path({
start: [400, 40],
segments: [
{ cubic: [[300, 40], [220, 200], [120, 200]], ease: 'easeOutQuad' },
{ wave: { to: [-20, 120], amplitude: 18, cycles: 2 } },
],
});
const p = swoop.getPoint(0.5); // halfway ALONG the route (by distance)
sprite.x = p.x; sprite.y = p.y;
sprite.rot = swoop.getAngle(0.5); // facing its direction of travel
getPoint(t) is O(log samples) — a binary search over the baked table — so
hundreds of followers per frame are cheap.
readonly length: number— Total geometric length of the path, in pixels.constructor(data: PathData, options: PathOptions = {})static fromJSON(json: string | PathData, options: PathOptions = {}): Path— Build a Path from a JSON string or an already-parsed data object.getPoint(t: number, out: Vec2 = { x: 0, y: 0 }): Vec2— The point att(0 = start, 1 = end) measured BY DISTANCE along the path (constant speed unless eased). Passoutto avoid allocating.getAngle(t: number): number— The direction of travel att, in radians (atan2 convention — feed it straight tosprite.rotso art faces along the path).
Types
PathData
interface PathData
The plain-data path notation — JSON-friendly: author it inline, in config
tables, or load it with loadJson.
start: PathPoint— Where the path begins,[x, y].segments: PathSegmentData[]— The chained segments, each continuing from the previous end point.ease?: PathEase— Ease applied across the WHOLE path's travel (on top of per-segment eases).
PathEase
type PathEase = EaseName | EaseFn
An ease across a segment or a whole path: a name, or your own function.
PathNotationApi
interface PathNotationApi
game.pathNotation: the chained path notation.
Path: typeof Path— A route baked from its plain-data notation;Path.fromJSONtakes a string too.
PathOptions
interface PathOptions
Parse-time options — transform the authored coordinates once, at the bake.
flipX?: number— Mirror every x about this vertical axis (flipX: W / 2flips a wave to the other side of the screen).flipY?: number— Mirror every y about this horizontal axis.offset?: PathPoint— Translate the whole path by[dx, dy].samplesPerSegment?: number— Samples baked per segment (the arc-length table resolution). Default 48 — raise for very long or very curly segments.
PathPoint
type PathPoint = [number, number]
A point in the data notation — [x, y].
PathSegmentData
interface PathSegmentData
One segment of the plain-data path notation. Every segment continues from the
path's current point; coordinates are absolute (transform at parse time via
PathOptions). Exactly one of the shape keys per segment.
line?: PathPoint— Straight line to[x, y].quad?: [PathPoint, PathPoint]— Quadratic bézier:[control, to].cubic?: [PathPoint, PathPoint, PathPoint]— Cubic bézier:[control1, control2, to].arc?: { center: PathPoint; to: number; ry?: number }— Elliptical arc about a centre. Starts at the current point (start angle and x-radius are derived from it); sweeps to absolute angleto(DEGREES — beyond ±360 keeps orbiting).rydefaults to the derived x-radius (circle).spiral?: { center: PathPoint; turns: number; endRadius: number }— Spiral about a centre: likearc, but the radius glides toendRadiusoverturnsfull revolutions (positive = clockwise, negative = counter).wave?: { to: PathPoint; amplitude: number; cycles: number; shape?: 'sine' | 'triangle' }— Sinusoidal wave: ride the straight chord totowhile oscillating perpendicular byamplitudepx overcyclesfull waves.shape: 'triangle'makes it a zigzag.ease?: PathEase— Ease applied across THIS segment's travel (name or function).


