Skip to main content
Version: Phaser v4.0.0

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

nametypeoptionaldescription
pointsArray.<Phaser.Math.Vector2> | Array.<number>Array.<Array.<number>>Yes

Scope: static

Extends

Phaser.Curves.Curve

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:


Public Methods

addPoint

<instance> addPoint(x, y)

Description:

Add a point to the current list of Vector2 points of the curve.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate of the point to add.
ynumberNoThe 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:

nametypeoptionaldescription
pointsArray.<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:

nametypeoptionaldescription
dataPhaser.Types.Curves.JSONCurveNoThe 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:

nametypeoptionaldescription
tnumberNoThe position along the curve to return. Where 0 is the start and 1 is the end.
outPhaser.Math.Vector2YesA 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:

nametypeoptionaldescription
divisionsnumberNoThe 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:

nametypeoptionaldescription
outPhaser.Math.Vector2YesA 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