Spline
A Spline Curve is a smooth curve that passes through a series of control points, using Catmull-Rom interpolation to produce a natural-looking path. Unlike a Bezier curve, every control point is visited exactly, making it easy to define a precise route for objects to follow.
Use a Spline Curve when you need a smooth path through multiple waypoints, such as a camera dolly track, a projectile flight path, or a patrol route for a game character. Points can be added at construction time or incrementally via addPoint and addPoints.
Constructor
new Spline([points])
Parameters
| name | type | optional | description |
|---|---|---|---|
| points | Array.<Phaser.Math.Vector2> | Array.<number> | Array.<Array.<number>> | Yes |
Scope: static
Extends
Source: src/curves/SplineCurve.js#L14
Since: 3.0.0
Inherited Members
From Phaser.Curves.Curve:
Public Members
points
points: Array.<Phaser.Math.Vector2>
Description:
The Vector2 points that configure the curve.
Source: src/curves/SplineCurve.js#L44
Since: 3.0.0
Inherited Methods
From Phaser.Curves.Curve:
- draw
- getBounds
- getDistancePoints
- getEndPoint
- getLength
- getLengths
- getPointAt
- getPoints
- getRandomPoint
- getSpacedPoints
- getTangent
- getTangentAt
- getTFromDistance
- getUtoTmapping
- updateArcLengths
Public Methods
addPoint
<instance> addPoint(x, y)
Description:
Add a point to the current list of Vector2 points of the curve.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x | number | No | The x coordinate of the point to add. |
| y | number | No | The y coordinate of the point to add. |
Returns: Phaser.Math.Vector2 - The new Vector2 added to the curve
Source: src/curves/SplineCurve.js#L97
Since: 3.0.0
addPoints
<instance> addPoints(points)
Description:
Add a list of points to the current list of Vector2 points of the curve.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| points | Array.<Phaser.Math.Vector2> | Array.<number> | Array.<Array.<number>> | No |
Returns: Phaser.Curves.Spline - This curve object.
Source: src/curves/SplineCurve.js#L57
Since: 3.0.0
fromJSON
<static> fromJSON(data)
Description:
Imports a JSON object containing this curve data.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| data | Phaser.Types.Curves.JSONCurve | No | The JSON object containing this curve data. |
Returns: Phaser.Curves.Spline - The spline curve created.
Source: src/curves/SplineCurve.js#L210
Since: 3.0.0
getPoint
<instance> getPoint(t, [out])
Description:
Get point at relative position in curve according to length.
Tags:
- generic
Parameters:
| name | type | optional | description |
|---|---|---|---|
| t | number | No | The position along the curve to return. Where 0 is the start and 1 is the end. |
| out | Phaser.Math.Vector2 | Yes | A Vector2 object to store the result in. If not given will be created. |
Returns: Phaser.Math.Vector2 - The coordinates of the point on the curve. If an out object was given this will be returned.
Source: src/curves/SplineCurve.js#L151
Since: 3.0.0
getResolution
<instance> getResolution(divisions)
Description:
Returns the resolution of this curve, which is the number of points used to approximate it per segment. For a Spline, this scales with the number of points and the requested divisions.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| divisions | number | No | The number of divisions per segment used when approximating the curve. |
Returns: number - The curve resolution.
Source: src/curves/SplineCurve.js#L136
Since: 3.0.0
getStartPoint
<instance> getStartPoint([out])
Description:
Gets the starting point on the curve.
Tags:
- generic
Parameters:
| name | type | optional | description |
|---|---|---|---|
| out | Phaser.Math.Vector2 | Yes | A Vector2 object to store the result in. If not given will be created. |
Overrides: Phaser.Curves.Curve#getStartPoint
Returns: Phaser.Math.Vector2 - The coordinates of the point on the curve. If an out object was given this will be returned.
Source: src/curves/SplineCurve.js#L117
Since: 3.0.0
toJSON
<instance> toJSON()
Description:
Exports a JSON object containing this curve data.
Returns: Phaser.Types.Curves.JSONCurve - The JSON object containing this curve data.
Source: src/curves/SplineCurve.js#L184
Since: 3.0.0