new CubicBezier(p0, p1, p2, p3)
name | type | description |
---|---|---|
p0 | Phaser.Math.Vector2 | Array.<Phaser.Math.Vector2> |
Start point, or an array of point pairs. |
p1 | Phaser.Math.Vector2 |
Control Point 1. |
p2 | Phaser.Math.Vector2 |
Control Point 2. |
p3 | Phaser.Math.Vector2 |
End Point. |
For a curve on a Path, false
means the Path will ignore this curve.
The quantity of arc length divisions within the curve.
An array of cached arc length values.
The default number of divisions within the curve.
Does the data of this curve need updating?
The start point of this curve.
The first control point of this curve.
The second control point of this curve.
The end point of this curve.
String based identifier for the type of curve.
Draws this curve to the specified graphics object.
name | type | arguments | Default | description |
---|---|---|---|---|
graphics | Phaser.GameObjects.Graphics |
The graphics object this curve should be drawn to. |
||
pointsTotal | number | <optional> | 32 |
The number of intermediary points that make up this curve. A higher number of points will result in a smoother curve. |
The graphics object this curve was drawn to. Useful for method chaining.
Returns a Rectangle where the position and dimensions match the bounds of this Curve.
You can control the accuracy of the bounds. The value given is used to work out how many points to plot across the curve. Higher values are more accurate at the cost of calculation speed.
name | type | arguments | Default | description |
---|---|---|---|---|
out | Phaser.Geom.Rectangle | <optional> |
The Rectangle to store the bounds in. If falsey a new object will be created. |
|
accuracy | number | <optional> | 16 |
The accuracy of the bounds calculations. |
A Rectangle object holding the bounds of this curve. If out
was given it will be this object.
Returns an array of points, spaced out X distance pixels apart. The smaller the distance, the larger the array will be.
name | type | description |
---|---|---|
distance | number |
The distance, in pixels, between each point along the curve. |
An Array of Point objects.
Get a point at the end of the curve.
name | type | arguments | description |
---|---|---|---|
out | Phaser.Math.Vector2 | <optional> |
Optional Vector object to store the result in. |
Vector2 containing the coordinates of the curves end point.
Get total curve arc length
The total length of the curve.
Get a list of cumulative segment lengths.
These lengths are
name | type | arguments | description |
---|---|---|---|
divisions | number | <optional> |
The number of divisions or segments. |
An array of cumulative lengths.
Get point at relative position in curve according to length.
name | type | arguments | description |
---|---|---|---|
t | number |
The position along the curve to return. Where 0 is the start and 1 is the end. |
|
out | Phaser.Math.Vector2 | <optional> |
A Vector2 object to store the result in. If not given will be created. |
The coordinates of the point on the curve. If an out
object was given this will be returned.
Get a point at a relative position on the curve, by arc length.
name | type | arguments | description |
---|---|---|---|
u | number |
The relative position, [0..1]. |
|
out | Phaser.Math.Vector2 | <optional> |
A point to store the result in. |
The point.
Get a sequence of evenly spaced points from the curve.
You can pass divisions
, stepRate
, or neither.
The number of divisions will be
divisions
, if divisions
> 0; orthis.getLength / stepRate
, if stepRate
> 0; orthis.defaultDivisions
1 + divisions
points will be returned.
name | type | arguments | description |
---|---|---|---|
divisions | number | <optional> |
The number of divisions to make. |
stepRate | number | <optional> |
The curve distance between points, implying |
out | array | Array.<Phaser.Math.Vector2> | <optional> |
An optional array to store the points in. |
An array of Points from the curve.
Get a random point from the curve.
name | type | arguments | description |
---|---|---|---|
out | Phaser.Math.Vector2 | <optional> |
A point object to store the result in. |
The point.
Returns the resolution of this curve.
name | type | description |
---|---|---|
divisions | number |
The amount of divisions used by this curve. |
The resolution of the curve.
Get a sequence of equally spaced points (by arc distance) from the curve.
1 + divisions
points will be returned.
name | type | arguments | Default | description |
---|---|---|---|---|
divisions | number | <optional> | this.defaultDivisions |
The number of divisions to make. |
stepRate | number | <optional> |
Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive. |
|
out | array | Array.<Phaser.Math.Vector2> | <optional> |
An optional array to store the points in. |
An array of points.
Gets the starting point on the curve.
name | type | arguments | description |
---|---|---|---|
out | Phaser.Math.Vector2 | <optional> |
A Vector2 object to store the result in. If not given will be created. |
The coordinates of the point on the curve. If an out
object was given this will be returned.
Given a distance in pixels, get a t to find p.
name | type | arguments | description |
---|---|---|---|
distance | number |
The distance, in pixels. |
|
divisions | number | <optional> |
Optional amount of divisions. |
The distance.
Get a unit vector tangent at a relative position on the curve. In case any sub curve does not implement its tangent derivation, 2 points a small delta apart will be used to find its gradient which seems to give a reasonable approximation
name | type | arguments | description |
---|---|---|---|
t | number |
The relative position on the curve, [0..1]. |
|
out | Phaser.Math.Vector2 | <optional> |
A vector to store the result in. |
Vector approximating the tangent line at the point t (delta +/- 0.0001)
Get a unit vector tangent at a relative position on the curve, by arc length.
name | type | arguments | description |
---|---|---|---|
u | number |
The relative position on the curve, [0..1]. |
|
out | Phaser.Math.Vector2 | <optional> |
A vector to store the result in. |
The tangent vector.
Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant.
name | type | arguments | description |
---|---|---|---|
u | number |
A float between 0 and 1. |
|
distance | number |
The distance, in pixels. |
|
divisions | number | <optional> |
Optional amount of divisions. |
The equidistant value.
Returns a JSON object that describes this curve.
The JSON object containing this curve data.
Calculate and cache the arc lengths.
Generates a curve from a JSON object.
name | type | description |
---|---|---|
data | Phaser.Types.Curves.JSONCurve |
The JSON object containing this curve data. |
The curve generated from the JSON object.