curves-and-paths
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCurves and Paths
曲线与路径
Creating paths from curves, getting points along them, drawing them with Graphics, and making sprites follow paths automatically using PathFollower in Phaser 4.
Key source paths: , , ,
Related skills: ../sprites-and-images/SKILL.md, ../graphics-and-shapes/SKILL.md, ../tweens/SKILL.md
src/curves/src/curves/path/src/gameobjects/pathfollower/src/gameobjects/components/PathFollower.js在Phaser 4中,从曲线创建路径、获取路径上的点、使用Graphics绘制路径,以及利用PathFollower让精灵自动沿路径移动。
核心源码路径: , , ,
相关技能: ../sprites-and-images/SKILL.md, ../graphics-and-shapes/SKILL.md, ../tweens/SKILL.md
src/curves/src/curves/path/src/gameobjects/pathfollower/src/gameobjects/components/PathFollower.jsQuick Start
快速开始
js
// In a Scene's create() method:
// 1. Create a Path starting at (50, 300)
const path = this.add.path(50, 300);
// 2. Add curves to the path
path.lineTo(200, 100);
path.splineTo([ new Phaser.Math.Vector2(300, 400), new Phaser.Math.Vector2(500, 200) ]);
path.lineTo(700, 300);
// 3. Draw the path using Graphics
const graphics = this.add.graphics();
graphics.lineStyle(2, 0xffffff, 1);
path.draw(graphics, 64);
// 4. Create a PathFollower sprite that moves along the path
const follower = this.add.follower(path, 50, 300, 'ship');
follower.startFollow({
duration: 5000,
rotateToPath: true,
repeat: -1,
yoyo: true
});js
// 在场景的create()方法中:
// 1. 创建一个起始点为(50, 300)的Path
const path = this.add.path(50, 300);
// 2. 向路径中添加曲线
path.lineTo(200, 100);
path.splineTo([ new Phaser.Math.Vector2(300, 400), new Phaser.Math.Vector2(500, 200) ]);
path.lineTo(700, 300);
// 3. 使用Graphics绘制路径
const graphics = this.add.graphics();
graphics.lineStyle(2, 0xffffff, 1);
path.draw(graphics, 64);
// 4. 创建一个沿路径移动的PathFollower精灵
const follower = this.add.follower(path, 50, 300, 'ship');
follower.startFollow({
duration: 5000,
rotateToPath: true,
repeat: -1,
yoyo: true
});Core Concepts
核心概念
Path
Path
A is a container that combines multiple Curves into one continuous compound curve. Curves in a Path do not need to be connected end-to-end. Only the order of curves affects point calculations along the path.
Phaser.Curves.PathCreated via factory: where x/y is the starting point.
this.add.path(x, y)Key properties:
- -- array of
curvesobjects in the PathPhaser.Curves.Curve - --
startPoint, the defined starting positionVector2 - -- boolean, if true
autoCloseappends the first point at the endgetPoints() - -- number (default: 12), divisions per curve when calling
defaultDivisionsgetPoints() - -- string, empty by default, for developer use
name
Phaser.Curves.Path通过工厂方法创建:,其中x/y为起始点。
this.add.path(x, y)关键属性:
- -- 路径中
curves对象的数组Phaser.Curves.Curve - --
startPoint类型,定义的起始位置Vector2 - -- 布尔值,若为true,
autoClose会在末尾追加第一个点getPoints() - -- 数字(默认值:12),调用
defaultDivisions时每条曲线的分段数getPoints() - -- 字符串,默认为空,供开发者使用
name
Curves
曲线
All curve types extend (the base class). Every curve supports:
Phaser.Curves.Curve- -- get a point at position t (0-1) based on curve parameterization
getPoint(t, out) - -- get a point at position u (0-1) based on arc length (evenly spaced)
getPointAt(u, out) - -- array of points along the curve
getPoints(divisions, stepRate, out) - -- array of equidistant points by arc length
getSpacedPoints(divisions, stepRate, out) - -- points spaced by pixel distance
getDistancePoints(distance) - -- total arc length in pixels
getLength() - -- bounding Rectangle
getBounds(out, accuracy) - /
getTangent(t, out)-- unit tangent vectorgetTangentAt(u, out) - /
getStartPoint(out)-- first/last pointsgetEndPoint(out) - -- random point on the curve
getRandomPoint(out) - -- render the curve onto a Graphics object
draw(graphics, pointsTotal) - -- boolean, when false the parent Path skips this curve
active
所有曲线类型都继承自(基类)。每条曲线都支持:
Phaser.Curves.Curve- -- 根据曲线参数化获取位置t(0-1)处的点
getPoint(t, out) - -- 根据弧长获取位置u(0-1)处的点(均匀分布)
getPointAt(u, out) - -- 沿曲线分布的点数组
getPoints(divisions, stepRate, out) - -- 按弧长等距分布的点数组
getSpacedPoints(divisions, stepRate, out) - -- 按像素距离间隔分布的点
getDistancePoints(distance) - -- 总弧长(以像素为单位)
getLength() - -- 边界矩形
getBounds(out, accuracy) - /
getTangent(t, out)-- 单位切向量getTangentAt(u, out) - /
getStartPoint(out)-- 第一个/最后一个点getEndPoint(out) - -- 曲线上的随机点
getRandomPoint(out) - -- 将曲线渲染到Graphics对象上
draw(graphics, pointsTotal) - -- 布尔值,若为false,父路径会跳过此曲线
active
PathFollower
PathFollower
A is a Sprite with the mixin. It uses an internal Tween (a number counter from 0 to 1) to advance along a Path each frame.
Phaser.GameObjects.PathFollowerComponents.PathFollowerCreated via factory:
this.add.follower(path, x, y, texture, frame)The PathFollower component provides:
- -- the
pathbeing followedPhaser.Curves.Path - -- the internal Tween driving movement
pathTween - --
pathOffset, offset added to path coordinatesVector2 - --
pathVector, current position on the pathVector2 - --
pathDelta, distance traveled since last frameVector2 - -- boolean, auto-rotate to face path direction
rotateToPath - -- number (degrees), added to auto-rotation
pathRotationOffset
Phaser.GameObjects.PathFollowerComponents.PathFollower通过工厂方法创建:
this.add.follower(path, x, y, texture, frame)PathFollower组件提供:
- -- 正在跟随的
pathPhaser.Curves.Path - -- 驱动移动的内部Tween
pathTween - --
pathOffset类型,添加到路径坐标的偏移量Vector2 - --
pathVector类型,路径上的当前位置Vector2 - --
pathDelta类型,自上一帧以来移动的距离Vector2 - -- 布尔值,自动旋转以面向路径方向
rotateToPath - -- 数字(度数),添加到自动旋转的偏移量
pathRotationOffset
Common Patterns
常见模式
Creating Paths with Chained Curves
使用链式曲线创建路径
Path has convenience methods that create curves starting from the previous end point:
js
const path = this.add.path(100, 500);
path.lineTo(300, 100); // straight line
path.cubicBezierTo(500, 100, 350, 50, 450, 50); // cubic bezier (endX, endY, cp1X, cp1Y, cp2X, cp2Y)
path.quadraticBezierTo(700, 400, 600, 100); // quadratic bezier (endX, endY, cpX, cpY)
path.splineTo([ // spline through points
new Phaser.Math.Vector2(750, 300),
new Phaser.Math.Vector2(600, 500)
]);
path.ellipseTo(50, 80, 0, 270, false, 0); // ellipse arc (xRadius, yRadius, startAngle, endAngle, clockwise, rotation)
path.circleTo(40); // shortcut for ellipseTo with equal radii and 0-360
// Jump to a new position without drawing (creates a gap)
path.moveTo(400, 400);
path.lineTo(500, 400);
// Close the path by connecting end to start
path.closePath();Path提供了便捷方法,可从之前的终点创建曲线:
js
const path = this.add.path(100, 500);
path.lineTo(300, 100); // 直线
path.cubicBezierTo(500, 100, 350, 50, 450, 50); // 三次贝塞尔曲线(终点X, 终点Y, 控制点1X, 控制点1Y, 控制点2X, 控制点2Y)
path.quadraticBezierTo(700, 400, 600, 100); // 二次贝塞尔曲线(终点X, 终点Y, 控制点X, 控制点Y)
path.splineTo([ // 穿过多个点的样条曲线
new Phaser.Math.Vector2(750, 300),
new Phaser.Math.Vector2(600, 500)
]);
path.ellipseTo(50, 80, 0, 270, false, 0); // 椭圆弧(X半径, Y半径, 起始角度, 结束角度, 顺时针, 旋转角度)
path.circleTo(40); // 半径相等且角度范围0-360的ellipseTo快捷方式
// 跳转到新位置而不绘制(创建间隙)
path.moveTo(400, 400);
path.lineTo(500, 400);
// 通过连接终点与起点闭合路径
path.closePath();Adding Standalone Curve Objects
添加独立曲线对象
js
const path = new Phaser.Curves.Path(0, 0);
// Add pre-constructed curve objects
const line = new Phaser.Curves.Line(new Phaser.Math.Vector2(0, 0), new Phaser.Math.Vector2(200, 200));
path.add(line);
const spline = new Phaser.Curves.Spline([ 200, 200, 300, 100, 400, 300 ]);
path.add(spline);
const ellipse = new Phaser.Curves.Ellipse(400, 300, 100, 60, 0, 360, false, 0);
path.add(ellipse);js
const path = new Phaser.Curves.Path(0, 0);
// 添加预构造的曲线对象
const line = new Phaser.Curves.Line(new Phaser.Math.Vector2(0, 0), new Phaser.Math.Vector2(200, 200));
path.add(line);
const spline = new Phaser.Curves.Spline([ 200, 200, 300, 100, 400, 300 ]);
path.add(spline);
const ellipse = new Phaser.Curves.Ellipse(400, 300, 100, 60, 0, 360, false, 0);
path.add(ellipse);Getting Points Along a Path
获取路径上的点
js
// Array of points (uses defaultDivisions per curve)
const points = path.getPoints();
// With explicit divisions per curve
const detailed = path.getPoints(32);
// Equally spaced points along the entire path
const spaced = path.getSpacedPoints(100);
// Single point at normalized position (0-1)
const midpoint = path.getPoint(0.5);
// Tangent vector at a position
const tangent = path.getTangent(0.5);
// Total path length in pixels
const length = path.getLength();
// Bounding rectangle
const bounds = path.getBounds();js
// 点数组(使用每条曲线的defaultDivisions)
const points = path.getPoints();
// 指定每条曲线的分段数
const detailed = path.getPoints(32);
// 沿整个路径等距分布的点
const spaced = path.getSpacedPoints(100);
// 归一化位置(0-1)处的单个点
const midpoint = path.getPoint(0.5);
// 某位置的切向量
const tangent = path.getTangent(0.5);
// 路径总长度(以像素为单位)
const length = path.getLength();
// 边界矩形
const bounds = path.getBounds();Drawing Paths with Graphics
使用Graphics绘制路径
js
const graphics = this.add.graphics();
// Draw entire path
graphics.lineStyle(2, 0x00ff00, 1);
path.draw(graphics, 64); // 64 = points per curve for smoothness
// Draw individual curves
graphics.lineStyle(1, 0xff0000, 1);
path.curves[0].draw(graphics, 32);
// Draw debug points
const points = path.getSpacedPoints(50);
points.forEach(p => {
graphics.fillStyle(0xffff00, 1);
graphics.fillCircle(p.x, p.y, 3);
});js
const graphics = this.add.graphics();
// 绘制整个路径
graphics.lineStyle(2, 0x00ff00, 1);
path.draw(graphics, 64); // 64 = 每条曲线的点数,用于保证平滑度
// 绘制单个曲线
graphics.lineStyle(1, 0xff0000, 1);
path.curves[0].draw(graphics, 32);
// 绘制调试点
const points = path.getSpacedPoints(50);
points.forEach(p => {
graphics.fillStyle(0xffff00, 1);
graphics.fillCircle(p.x, p.y, 3);
});PathFollower Sprite
PathFollower精灵
js
const path = this.add.path(100, 200);
path.lineTo(400, 400);
path.lineTo(700, 200);
// Create follower
const enemy = this.add.follower(path, 100, 200, 'enemy');
// Start following with config
enemy.startFollow({
duration: 3000, // ms to traverse path
positionOnPath: true, // snap to path start position
rotateToPath: true, // auto-rotate to face direction
rotationOffset: 90, // offset added to auto-rotation (degrees)
repeat: -1, // -1 = infinite repeat
yoyo: true, // reverse on each repeat
from: 0, // start position on path (0-1)
to: 1, // end position on path (0-1)
startAt: 0, // initial seek position
ease: 'Sine.easeInOut' // any valid Phaser ease
});
// Control during playback
enemy.pauseFollow();
enemy.resumeFollow();
enemy.stopFollow();
enemy.isFollowing(); // returns boolean
// Change path at runtime
enemy.setPath(newPath);
enemy.setPath(newPath, { duration: 2000 }); // auto-starts
// Set rotation independently
enemy.setRotateToPath(true, 90); // (value, offsetDegrees)js
const path = this.add.path(100, 200);
path.lineTo(400, 400);
path.lineTo(700, 200);
// 创建跟随器
const enemy = this.add.follower(path, 100, 200, 'enemy');
// 配置并开始跟随
enemy.startFollow({
duration: 3000, // 遍历路径的毫秒数
positionOnPath: true, // 对齐到路径起始位置
rotateToPath: true, // 自动旋转以面向移动方向
rotationOffset: 90, // 添加到自动旋转的偏移量(度数)
repeat: -1, // -1 = 无限重复
yoyo: true, // 每次重复时反向移动
from: 0, // 路径上的起始位置(0-1)
to: 1, // 路径上的结束位置(0-1)
startAt: 0, // 初始定位位置
ease: 'Sine.easeInOut' // 任何有效的Phaser缓动函数
});
// 播放期间控制
enemy.pauseFollow();
enemy.resumeFollow();
enemy.stopFollow();
enemy.isFollowing(); // 返回布尔值
// 运行时更改路径
enemy.setPath(newPath);
enemy.setPath(newPath, { duration: 2000 }); // 自动开始跟随
// 独立设置旋转
enemy.setRotateToPath(true, 90); // (是否开启, 偏移度数)PathFollower with Simple Duration
仅指定时长的PathFollower
js
// Shorthand: pass just a duration number
enemy.startFollow(5000);
// Equivalent to:
enemy.startFollow({ duration: 5000 });js
// 简写:仅传入时长数字
enemy.startFollow(5000);
// 等同于:
enemy.startFollow({ duration: 5000 });All Curve Types
所有曲线类型
| Curve | Class | Constructor Params | Description |
|---|---|---|---|
| Line | | | Straight line segment between two points |
| Spline | | | Catmull-Rom spline through control points |
| CubicBezier | | | Cubic Bezier with start, 2 control points, end |
| QuadraticBezier | | | Quadratic Bezier with start, 1 control point, end |
| Ellipse | | | Elliptical arc; angles in degrees; yRadius defaults to xRadius |
| 曲线 | 类 | 构造参数 | 描述 |
|---|---|---|---|
| 直线 | | | 两点之间的直线段 |
| 样条曲线 | | | 穿过控制点的Catmull-Rom样条曲线 |
| 三次贝塞尔曲线 | | | 包含起点、2个控制点和终点的三次贝塞尔曲线 |
| 二次贝塞尔曲线 | | | 包含起点、1个控制点和终点的二次贝塞尔曲线 |
| 椭圆 | | | 椭圆弧;角度以度数为单位;Y半径默认等于X半径 |
Ellipse Curve Properties
椭圆曲线属性
The Ellipse curve has get/set properties for runtime modification:
- ,
x-- center positiony - ,
xRadius-- radiiyRadius - ,
startAngle-- in degrees (get/set convert to/from radians internally)endAngle - -- boolean
clockwise - -- in radians
rotation - -- rotation in degrees (alternative to
angle)rotation - /
setWidth(value)-- sets radius to value/2setHeight(value)
椭圆曲线支持通过get/set属性在运行时修改:
- ,
x-- 中心位置y - ,
xRadius-- 半径yRadius - ,
startAngle-- 度数(get/set会在内部与弧度互相转换)endAngle - -- 布尔值
clockwise - -- 弧度
rotation - -- 旋转角度(度数,
angle的替代属性)rotation - /
setWidth(value)-- 将半径设置为value/2setHeight(value)
API Quick Reference
API快速参考
Path (Phaser.Curves.Path
)
Phaser.Curves.PathPath(Phaser.Curves.Path
)
Phaser.Curves.Path| API | Type | Description |
|---|---|---|
| method | Append any Curve to the path |
| method | Add a Line from current end point |
| method | Add a Spline from current end point |
| method | Add CubicBezier from current end point |
| method | Add QuadraticBezier from current end point |
| method | Add Ellipse arc from current end point |
| method | Shortcut for ellipseTo with equal radii |
| method | Move end point without drawing (creates gap) |
| method | Add Line from end to start if not already closed |
| method | Point at normalized position (0-1) on entire path |
| method | Array of points, divisions per curve |
| method | Equidistant points along entire path |
| method | Random point anywhere on the path |
| method | Path starting point |
| method | Path ending point |
| method | Unit tangent vector at position t |
| method | Return the Curve at normalized position t |
| method | Total path length in pixels |
| method | Array of cumulative curve lengths |
| method | Bounding Rectangle |
| method | Draw all curves onto a Graphics object |
| method | Serialization |
| method | Force recalculation of cached lengths |
| method | Clear internal references |
| API | 类型 | 描述 |
|---|---|---|
| 方法 | 向路径中追加任意曲线 |
| 方法 | 从当前终点添加一条直线 |
| 方法 | 从当前终点添加一条样条曲线 |
| 方法 | 从当前终点添加一条三次贝塞尔曲线 |
| 方法 | 从当前终点添加一条二次贝塞尔曲线 |
| 方法 | 从当前终点添加一段椭圆弧 |
| 方法 | 半径相等的ellipseTo快捷方式 |
| 方法 | 移动终点而不绘制(创建间隙) |
| 方法 | 如果尚未闭合,添加一条从终点到起点的直线 |
| 方法 | 整个路径上归一化位置(0-1)处的点 |
| 方法 | 点数组,按每条曲线的分段数生成 |
| 方法 | 沿整个路径等距分布的点 |
| 方法 | 路径上任意位置的随机点 |
| 方法 | 路径起始点 |
| 方法 | 路径终点 |
| 方法 | 位置t处的单位切向量 |
| 方法 | 返回归一化位置t处的曲线 |
| 方法 | 路径总长度(以像素为单位) |
| 方法 | 累积曲线长度的数组 |
| 方法 | 边界矩形 |
| 方法 | 将所有曲线绘制到Graphics对象上 |
| 方法 | 序列化与反序列化 |
| 方法 | 强制重新计算缓存的长度 |
| 方法 | 清除内部引用 |
Base Curve (Phaser.Curves.Curve
)
Phaser.Curves.Curve基础曲线(Phaser.Curves.Curve
)
Phaser.Curves.Curve| API | Type | Description |
|---|---|---|
| method | Point at parameter t (0-1) -- abstract, each subclass implements |
| method | Point at arc-length position u (0-1) -- evenly spaced |
| method | Array of points |
| method | Equidistant points by arc length |
| method | Points spaced by pixel distance |
| method | Total curve arc length |
| method | Unit tangent vector |
| method | Convert pixel distance to t value |
| method | Render onto Graphics (default 32 points) |
| method | Bounding Rectangle |
| | When false, parent Path skips this curve |
| | Default 5 for standalone curves |
| | Precision for arc length calculations (default 100) |
| API | 类型 | 描述 |
|---|---|---|
| 方法 | 参数t(0-1)处的点 -- 抽象方法,每个子类实现 |
| 方法 | 弧长位置u(0-1)处的点 -- 均匀分布 |
| 方法 | 点数组 |
| 方法 | 按弧长等距分布的点数组 |
| 方法 | 按像素距离间隔分布的点 |
| 方法 | 曲线总弧长 |
| 方法 | 单位切向量 |
| 方法 | 将像素距离转换为t值 |
| 方法 | 渲染到Graphics上(默认32个点) |
| 方法 | 边界矩形 |
| | 若为false,父路径会跳过此曲线 |
| | 独立曲线的默认值为5 |
| | 弧长计算的精度(默认值100) |
PathFollower Component
PathFollower组件
| API | Type | Description |
|---|---|---|
| method | Set a new Path (optionally auto-start) |
| method | Begin following; config = duration number or PathConfig |
| method | Pause movement |
| method | Resume paused movement |
| method | Stop following |
| method | Returns true if actively moving on path |
| method | Enable/disable auto-rotation with offset |
| | Current path reference |
| | Internal tween driving movement |
| | Offset from path coordinates |
| | Current position on the path |
| | Movement delta since last update |
| | Auto-rotate to path direction |
| | Rotation offset in degrees |
| API | 类型 | 描述 |
|---|---|---|
| 方法 | 设置新路径(可选择自动开始跟随) |
| 方法 | 开始跟随;config为时长数字或PathConfig对象 |
| 方法 | 暂停移动 |
| 方法 | 恢复暂停的移动 |
| 方法 | 停止跟随 |
| 方法 | 如果正在沿路径移动则返回true |
| 方法 | 启用/禁用带偏移量的自动旋转 |
| | 当前路径引用 |
| | 驱动移动的内部补间 |
| | 与路径坐标的偏移量 |
| | 路径上的当前位置 |
| | 自上次更新以来的移动增量 |
| | 自动旋转以面向路径方向 |
| | 旋转偏移量(度数) |
PathConfig (Phaser.Types.GameObjects.PathFollower.PathConfig
)
Phaser.Types.GameObjects.PathFollower.PathConfigPathConfig(Phaser.Types.GameObjects.PathFollower.PathConfig
)
Phaser.Types.GameObjects.PathFollower.PathConfig| Property | Type | Default | Description |
|---|---|---|---|
| | 1000 | Time in ms to traverse the path |
| | 0 | Start position on path (0-1) |
| | 1 | End position on path (0-1) |
| | false | Snap follower to path start on begin |
| | false | Auto-rotate to face path direction |
| | 0 | Degrees added to auto-rotation |
| | 0 | Initial seek position on path (0-1) |
The config also accepts all standard Tween properties: , , , , , , etc.
easerepeatyoyodelayholdonComplete| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | 1000 | 遍历路径的时间(毫秒) |
| | 0 | 路径上的起始位置(0-1) |
| | 1 | 路径上的结束位置(0-1) |
| | false | 开始时将跟随器对齐到路径起点 |
| | false | 自动旋转以面向路径方向 |
| | 0 | 添加到自动旋转的偏移量(度数) |
| | 0 | 路径上的初始定位位置(0-1) |
该配置还支持所有标准Tween属性:, , , , , 等。
easerepeatyoyodelayholdonCompleteGotchas
注意事项
-
vs
getPoint(t)on curves.getPointAt(u)uses the raw curve parameter t, which does not produce evenly spaced points on most curve types.getPointmaps through arc length for even spacing. On a Path,getPointAtalready accounts for arc length across the whole path.getPoint -
Pathcreates an inactive curve. The
moveTopseudo-curve hasMoveToand zero length. It only repositions the end point for the next curve. It does not draw anything and is skipped byactive: falseandgetPoints().draw() -
PathFollower uses a Tween internally. Theconfig is passed to
startFollow. All tween properties (ease, delay, repeat, yoyo, callbacks) work. The tween is set toscene.tweens.addCounter()automatically.persist: true -
PathFollower offset behavior. When(default), the follower's current position becomes the offset from the path start. When
positionOnPath: false, the follower snaps to the path's start point and the offset is zeroed.positionOnPath: true -
Ellipse angles are in degrees. The constructor and/
startAngleproperties accept degrees. Internally they are stored as radians. TheendAngleproperty is in radians, butrotationis in degrees.angle -
vs
closePath.autoCloseadds an explicit Line curve from end to start.closePath()only affectsautoClose = trueandgetPoints()output by appending the first point, without adding a curve.getSpacedPoints() -
Cached lengths can go stale.caches results based on array length only. If you modify a curve's control points, call
getCurveLengths()to force recalculation.path.updateArcLengths() -
parameter order with numbers. When passing numbers:
cubicBezierTo. The end point comes first, not the control points. When passing Vector2 objects:cubicBezierTo(endX, endY, cp1X, cp1Y, cp2X, cp2Y).cubicBezierTo(cp1, cp2, endPoint) -
Spline needs at least 4 points. The Catmull-Rom interpolation used by Spline works best with 4+ points. With fewer points, the curve may not behave as expected.
-
Line curveis 1. Unlike other curves (default 100), Line overrides this to 1 since a line is inherently uniform. No need to adjust it.
arcLengthDivisions
-
曲线上的与
getPoint(t):getPointAt(u)使用原始曲线参数t,在大多数曲线类型上不会生成均匀分布的点。getPoint通过弧长映射实现均匀分布。在Path上,getPointAt已考虑整个路径的弧长。getPoint -
Path的会创建非活动曲线:
moveTo伪曲线的MoveTo且长度为0,它仅重新定位下一条曲线的终点,不会绘制任何内容,且会被active: false和getPoints()跳过。draw() -
PathFollower内部使用Tween:配置会传递给
startFollow。所有补间属性(缓动、延迟、重复、往返、回调)均有效。补间会自动设置为scene.tweens.addCounter()。persist: true -
PathFollower的偏移行为:当(默认值)时,跟随器的当前位置会成为与路径起点的偏移量。当
positionOnPath: false时,跟随器会对齐到路径起点,偏移量归零。positionOnPath: true -
椭圆角度以度数为单位:构造函数和/
startAngle属性接受度数,内部以弧度存储。endAngle属性以弧度为单位,而rotation以度数为单位。angle -
与
closePath的区别:autoClose会添加一条从终点到起点的显式直线曲线。closePath()仅会在autoClose = true和getPoints()的输出中追加第一个点,不会添加曲线。getSpacedPoints() -
缓存的长度可能失效:仅根据数组长度缓存结果。如果修改了曲线的控制点,请调用
getCurveLengths()强制重新计算。path.updateArcLengths() -
的数字参数顺序:传入数字时顺序为:
cubicBezierTo,终点在前,而非控制点。传入Vector2对象时顺序为:cubicBezierTo(endX, endY, cp1X, cp1Y, cp2X, cp2Y)。cubicBezierTo(cp1, cp2, endPoint) -
样条曲线至少需要4个点:样条曲线使用的Catmull-Rom插值在4个及以上点时效果最佳。点数量较少时,曲线行为可能不符合预期。
-
直线曲线的为1:与其他曲线(默认值100)不同,直线会覆盖此值为1,因为直线本身是均匀的,无需调整。
arcLengthDivisions
Source File Map
源码文件映射
| File | Purpose |
|---|---|
| Path class -- combines multiple curves, factory registered as |
| MoveTo pseudo-curve for creating gaps in paths |
| Base Curve class -- shared methods for all curve types |
| Line curve (two-point segment) |
| Spline curve (Catmull-Rom through multiple points) |
| Cubic Bezier curve (4 control points) |
| Quadratic Bezier curve (3 control points) |
| Ellipse/arc curve with angle and rotation support |
| PathFollower Game Object (extends Sprite + PathFollower mixin) |
| |
| PathFollower component mixin (setPath, startFollow, pathUpdate, etc.) |
| PathConfig typedef |
| 文件 | 用途 |
|---|---|
| Path类 -- 组合多条曲线,工厂方法注册为 |
| MoveTo伪曲线,用于在路径中创建间隙 |
| 基础Curve类 -- 所有曲线类型的共享方法 |
| 直线曲线(两点线段) |
| 样条曲线(穿过多个点的Catmull-Rom曲线) |
| 三次贝塞尔曲线(4个控制点) |
| 二次贝塞尔曲线(3个控制点) |
| 椭圆/圆弧曲线,支持角度和旋转 |
| PathFollower游戏对象(继承Sprite + PathFollower混合类) |
| |
| PathFollower组件混合类(setPath、startFollow、pathUpdate等) |
| PathConfig类型定义 |