phaserjs/phaser/curves-and-paths

Claude Code and agent skill by phaserjs/phaser

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Phaser 4 curves and paths: Phaser.Curves.Path (this.add.path) with lineTo, splineTo, cubicBezierTo, quadraticBezierTo, ellipseTo, moveTo and closePath; the Line, Spline, CubicBezier, QuadraticBezier and Ellipse curves; getPoint, getPointAt, getSpacedPoints, getTangent and getLength; drawing a path with Graphics; and PathFollower (this.add.follower, startFollow, rotateToPath). Use when moving an enemy or a car along a route, making a winding track, attack patterns, placing objects evenly along a curve, or drawing a smooth curved line. Corrects common mistakes: the end point comes first in cubicBezierTo and quadraticBezierTo, Ellipse angles are degrees, getPoint on a Curve isn't evenly spaced, edited curves keep stale cached lengths. Triggers on: path, curve, spline, bezier, PathFollower, follower, startFollow, getPoint, getSpacedPoints, follow a path.

Install

npx vskill@latest install phaserjs/phaser/curves-and-paths

SKILL.md

The same SKILL.md was published earlier as phaserjs/phaser/curves-and-paths.

Curves and paths

Building a Path from curves, reading points along it, drawing it, and moving a sprite along it with a PathFollower.

Source: src/curves/ (one file per curve, Curve.js is the base), src/curves/path/Path.js, src/gameobjects/components/PathFollower.js, src/gameobjects/pathfollower/. Related: tweens, graphics-and-shapes, geometry-and-math.

Quick start

js
const { width, height } = this.scale;
const path = this.add.path(50, height / 2); // the start point
path.lineTo(250, 150);
path.splineTo([ 400, 600, 650, 200, 850, 500 ]);
path.lineTo(width - 50, height / 2);
const graphics = this.add.graphics();
graphics.lineStyle(2, 0xffffff);
path.draw(graphics, 64);
const ship = this.add.follower(path, 50, height / 2, 'ship');
ship.startFollow({
duration: 5000,
rotateToPath: true,
yoyo: true,
repeat: -1,
ease: 'Sine.easeInOut'
});

this.add.path(x, y) is the same as new Phaser.Curves.Path(x, y). A Path isn't a Game Object and isn't drawn by itself.

Building a Path

Each method starts the new curve at the end of the last one:

js
const path = new Phaser.Curves.Path(100, 500);
path.lineTo(300, 100);
path.cubicBezierTo(500, 100, 350, 0, 450, 0); // END x, y first, then control 1, control 2
path.quadraticBezierTo(700, 400, 600, 100); // END x, y first, then the control point
path.splineTo([ 750, 300, 600, 500 ]); // through these points
path.ellipseTo(50, 80, 0, 270, false, 0); // xRadius, yRadius, startAngle, endAngle, clockwise, rotation (degrees)
path.circleTo(40); // radius, clockwise, rotation
path.moveTo(400, 600); // a gap: the next curve starts here
path.lineTo(500, 600);
path.closePath(); // a line back to the start point
  • With numbers, cubicBezierTo and quadraticBezierTo take the end point first. With Vector2s the order is control points then end: cubicBezierTo(cp1, cp2, end), quadraticBezierTo(control, end). They must be Phaser.Math.Vector2 instances, not plain objects.
  • splineTo(points) takes Vector2s, { x, y } objects, [ x, y ] pairs or flat numbers. It adds the path's end point to the start of the array you pass, so don't reuse that array.
  • ellipseTo places the ellipse so its start angle is on the path's end point. All its angles are degrees.
  • path.add(curve) adds any curve. lineTo, moveTo, and the others return the Path, so they chain.
  • path.toJSON() and new Phaser.Curves.Path(json) save and load a path.

Curves

CurveConstructor
Phaser.Curves.Line(p0, p1) Vector2s, or ([ x0, y0, x1, y1 ])
Phaser.Curves.Spline(points): Vector2s, objects, [ x, y ] pairs or flat numbers. A Catmull-Rom curve through every point. Two or more points.
Phaser.Curves.CubicBezier(start, control1, control2, end) Vector2s, or an array of 8 numbers
Phaser.Curves.QuadraticBezier(start, control, end) Vector2s, or an array of 6 numbers
Phaser.Curves.Ellipse(x, y, xRadius, yRadius = xRadius, startAngle = 0, endAngle = 360, clockwise = false, rotation = 0) or a config object. Angles in degrees.

On an Ellipse, startAngle, endAngle and angle are degrees, but rotation is radians.

Reading points

js
const path = this.add.path(100, 100).lineTo(500, 100).lineTo(500, 400);
const pos = new Phaser.Math.Vector2();
path.getPoint(0.5, pos); // half way along the whole path, by distance
path.getTangent(0.5).angle(); // direction there, in radians
path.getLength(); // in pixels
path.getSpacedPoints(10); // 11 points, evenly spaced, from start to end
path.getPoints(16); // 16 divisions per curve: for drawing, not evenly spaced
path.getBounds(); // a Phaser.Geom.Rectangle
path.getRandomPoint();
  • On a Path, t (0 to 1) is a fraction of the path's length. On a single Curve, getPoint(t) follows the curve's own parameter, which bunches up where the curve bends. Use curve.getPointAt(u) and curve.getTangentAt(u) for even spacing.
  • path.getPoint(t) returns null for t above 1.
  • Pass an out Vector2 in an update loop, so it doesn't make a new one each frame.
  • curve.getDistancePoints(20) gives points 20 pixels apart along a curve.
After editing a curve

Lengths are cached. If you move a curve's points, update the curve, then the path:

js
const path = this.add.path(100, 500).lineTo(300, 100).cubicBezierTo(500, 100, 350, 0, 450, 0);
const curve = path.curves[1];
curve.p1.set(300, 200); // the CubicBezier's first control point
curve.updateArcLengths();
path.updateArcLengths();

Drawing

path.draw(graphics, pointsPerCurve = 32) strokes each curve with the current lineStyle. Each curve is a separate stroke, so a thick line has notches at the corners between curves. To stroke the whole path as one line, with joins at the corners:

js
const path = this.add.path(100, 500).lineTo(300, 100).splineTo([ 500, 300, 700, 100 ]);
const graphics = this.add.graphics();
graphics.lineStyle(12, 0x00ff00);
graphics.strokePoints(path.getPoints(32), false);

getPoints skips the gaps made by moveTo, so this joins across them. See graphics-and-shapes for line joins.

PathFollower

this.add.follower(path, x, y, texture, frame) makes a Sprite which follows a path. It moves itself in preUpdate, so it must be in the Scene, as this.add.follower makes it.

js
const path = this.add.path(100, 100).lineTo(900, 100).lineTo(900, 600);
const enemy = this.add.follower(path, 0, 0, 'enemy');
enemy.startFollow({
duration: 4000, // ms for the whole path. Default 1000
positionOnPath: true, // move to the path's start first
rotateToPath: true,
rotationOffset: 90, // degrees, for art that faces up
from: 0, // part of the path to follow, 0 to 1
to: 1,
startAt: 0.25, // start a quarter of the way along
ease: 'Sine.easeInOut', // and any other tween key: delay, repeat, yoyo, onComplete...
onComplete: () => enemy.destroy()
});
  • startFollow(duration) takes a number too.
  • The config makes a number tween with this.tweens.addCounter, stored as enemy.pathTween. Every tween key works, such as repeat, yoyo, delay and the callbacks. Callbacks receive that tween, not the follower.
  • Without positionOnPath, the follower keeps its distance from the path's start: the whole path is moved by the difference between the follower's position and the path's start.
  • pauseFollow(), resumeFollow(), stopFollow(), isFollowing(), setRotateToPath(true, offsetDegrees).
  • enemy.pathVector is the follower's position on the path; pathDelta is how far it moved this frame.
  • setPath(newPath) changes the path and starts following it at once, with the last config. setPath(newPath, config) uses a new one.

To move something which isn't a Sprite, such as a Container or Text, tween a value and read the path:

js
const path = this.add.path(100, 100).circleTo(150);
const pos = new Phaser.Math.Vector2();
const label = this.add.text(0, 0, 'Hello');
this.tweens.addCounter({
from: 0,
to: 1,
duration: 3000,
repeat: -1,
onUpdate: (tween) =>
{
path.getPoint(tween.getValue(), pos);
label.setPosition(pos.x, pos.y);
}
});

Gotchas

  • Bezier argument order. With numbers, the end point comes first: cubicBezierTo(endX, endY, cp1X, cp1Y, cp2X, cp2Y).
  • Eases that overshoot break following. Back and Elastic push the value past 0 or 1, and path.getPoint returns null past 1. Use eases which stay inside 0 to 1 on a follower.
  • `startAt` replaces `onStart`. When startAt is set, startFollow uses onStart itself to seek, so your onStart callback is lost. startFollow also writes from, to, persist and onStart into the config object you pass.
  • Stop a follower before destroying it. The follower doesn't stop its pathTween when destroyed, so a tween with repeat: -1 keeps running in the TweenManager until the Scene shuts down. Call stopFollow() first.
  • `moveTo` doesn't draw, but getPoints() and getSpacedPoints() skip over the gap, and getPoint counts it as zero length.
  • `autoClose` vs `closePath()`. closePath() adds a line curve back to the start. path.autoClose = true only adds the first point to the end of getPoints() and getSpacedPoints().

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
39,633
Repository forks
7,130
7-day trend score
53

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 May 2026, 6 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Grok Build (Cursor)
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/phaserjs/phaser/curves-and-paths/badge)](https://verified-skill.com/skills/phaserjs/phaser/curves-and-paths)

Something wrong with this skill or its page? Tell us.