Class: CubicBezier

Phaser.Curves. CubicBezier

A higher-order Bézier curve constructed of four points.


new CubicBezier(p0, p1, p2, p3)

Parameters:
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.

Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 14)

Extends

Members


active :boolean

For a curve on a Path, false means the Path will ignore this curve.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • true
Source: src/curves/Curve.js (Line 80)

arcLengthDivisions :integer

The quantity of arc length divisions within the curve.

Type:
  • integer
Since: 3.0.0
Inherited From:
Default Value:
  • 100
Source: src/curves/Curve.js (Line 50)

cacheArcLengths :Array.<number>

An array of cached arc length values.

Type:
  • Array.<number>
Since: 3.0.0
Inherited From:
Default Value:
  • []
Source: src/curves/Curve.js (Line 60)

defaultDivisions :integer

The default number of divisions within the curve.

Type:
  • integer
Since: 3.0.0
Inherited From:
Default Value:
  • 5
Source: src/curves/Curve.js (Line 40)

needsUpdate :boolean

Does the data of this curve need updating?

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • true
Source: src/curves/Curve.js (Line 70)

p0 :Phaser.Math.Vector2

The start point of this curve.

Type:
Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 47)

p1 :Phaser.Math.Vector2

The first control point of this curve.

Type:
Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 56)

p2 :Phaser.Math.Vector2

The second control point of this curve.

Type:
Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 65)

p3 :Phaser.Math.Vector2

The end point of this curve.

Type:
Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 74)

type :string

String based identifier for the type of curve.

Type:
  • string
Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 31)

Methods


<static> fromJSON(data)

Generates a curve from a JSON object.

Parameters:
Name Type Description
data Phaser.Types.Curves.JSONCurve

The JSON object containing this curve data.

Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 199)
Returns:

The curve generated from the JSON object.

Type
Phaser.Curves.CubicBezier

draw(graphics [, pointsTotal])

Draws this curve to the specified graphics object.

Parameters:
Name Type Argument Default Description
graphics Phaser.GameObjects.Graphics

The graphics object this curve should be drawn to.

pointsTotal integer <optional>
32

The number of intermediary points that make up this curve. A higher number of points will result in a smoother curve.

Since: 3.0.0
Overrides:
Source: src/curves/CubicBezierCurve.js (Line 143)
Returns:

The graphics object this curve was drawn to. Useful for method chaining.

Type
Phaser.GameObjects.Graphics

getBounds( [out] [, accuracy])

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.

Parameters:
Name Type Argument Default Description
out Phaser.Geom.Rectangle <optional>

The Rectangle to store the bounds in. If falsey a new object will be created.

accuracy integer <optional>
16

The accuracy of the bounds calculations.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 135)
Returns:

A Rectangle object holding the bounds of this curve. If out was given it will be this object.

Type
Phaser.Geom.Rectangle

getDistancePoints(distance)

Returns an array of points, spaced out X distance pixels apart. The smaller the distance, the larger the array will be.

Parameters:
Name Type Description
distance integer

The distance, in pixels, between each point along the curve.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 169)
Returns:

An Array of Point objects.

Type
Array.<Phaser.Geom.Point>

getEndPoint( [out])

Get a point at the end of the curve.

Parameters:
Name Type Argument Description
out Phaser.Math.Vector2 <optional>

Optional Vector object to store the result in.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 189)
Returns:

Vector2 containing the coordinates of the curves end point.

Type
Phaser.Math.Vector2

getLength()

Get total curve arc length

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 206)
Returns:

The total length of the curve.

Type
number

getLengths( [divisions])

Get a list of cumulative segment lengths.

These lengths are

  • [0] 0
  • [1] The first segment
  • [2] The first and second segment
  • ...
  • [divisions] All segments
Parameters:
Name Type Argument Description
divisions integer <optional>

The number of divisions or segments.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 222)
Returns:

An array of cumulative lengths.

Type
Array.<number>

getPoint(t [, out])

Get point at relative position in curve according to length.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 118)
Returns:

The coordinates of the point on the curve. If an out object was given this will be returned.

Type
Phaser.Math.Vector2

getPointAt(u [, out])

Get a point at a relative position on the curve, by arc length.

Parameters:
Name Type Argument Description
u number

The relative position, [0..1].

out Phaser.Math.Vector2 <optional>

A point to store the result in.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 278)
Returns:

The point.

Type
Phaser.Math.Vector2

getPoints( [divisions] [, stepRate] [, out])

Get a sequence of evenly spaced points from the curve.

You can pass divisions, stepRate, or neither.

The number of divisions will be

  1. divisions, if divisions > 0; or
  2. this.getLength / stepRate, if stepRate > 0; or
  3. this.defaultDivisions

1 + divisions points will be returned.

Parameters:
Name Type Argument Description
divisions integer <optional>

The number of divisions to make.

stepRate number <optional>

The curve distance between points, implying divisions.

out array | Array.<Phaser.Math.Vector2> <optional>

An optional array to store the points in.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 300)
Returns:

An array of Points from the curve.

Type
array | Array.<Phaser.Math.Vector2>

getRandomPoint( [out])

Get a random point from the curve.

Parameters:
Name Type Argument Description
out Phaser.Math.Vector2 <optional>

A point object to store the result in.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 349)
Returns:

The point.

Type
Phaser.Math.Vector2

getResolution(divisions)

Returns the resolution of this curve.

Parameters:
Name Type Description
divisions number

The amount of divisions used by this curve.

Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 103)
Returns:

The resolution of the curve.

Type
number

getSpacedPoints( [divisions] [, stepRate] [, out])

Get a sequence of equally spaced points (by arc distance) from the curve.

1 + divisions points will be returned.

Parameters:
Name Type Argument Default Description
divisions integer <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.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 370)
Returns:

An array of points.

Type
Array.<Phaser.Math.Vector2>

getStartPoint( [out])

Gets the starting point on the curve.

Parameters:
Name Type Argument Description
out Phaser.Math.Vector2 <optional>

A Vector2 object to store the result in. If not given will be created.

Since: 3.0.0
Overrides:
Source: src/curves/CubicBezierCurve.js (Line 84)
Returns:

The coordinates of the point on the curve. If an out object was given this will be returned.

Type
Phaser.Math.Vector2

getTangent(t [, out])

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

Parameters:
Name Type Argument Description
t number

The relative position on the curve, [0..1].

out Phaser.Math.Vector2 <optional>

A vector to store the result in.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 430)
Returns:

Vector approximating the tangent line at the point t (delta +/- 0.0001)

Type
Phaser.Math.Vector2

getTangentAt(u [, out])

Get a unit vector tangent at a relative position on the curve, by arc length.

Parameters:
Name Type Argument Description
u number

The relative position on the curve, [0..1].

out Phaser.Math.Vector2 <optional>

A vector to store the result in.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 472)
Returns:

The tangent vector.

Type
Phaser.Math.Vector2

getTFromDistance(distance [, divisions])

[description]

Parameters:
Name Type Argument Description
distance integer

[description]

divisions integer <optional>

[description]

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 493)
Returns:

[description]

Type
number

getUtoTmapping(u, distance [, divisions])

[description]

Parameters:
Name Type Argument Description
u number

[description]

distance integer

[description]

divisions integer <optional>

[description]

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 516)
Returns:

[description]

Type
number

toJSON()

Returns a JSON object that describes this curve.

Since: 3.0.0
Source: src/curves/CubicBezierCurve.js (Line 176)
Returns:

The JSON object containing this curve data.

Type
Phaser.Types.Curves.JSONCurve

updateArcLengths()

Calculate and cache the arc lengths.

Since: 3.0.0
Inherited From:
Source: src/curves/Curve.js (Line 597)
See:
  • Phaser.Curves.Curve#getLengths()