Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Curves . QuadraticBezier

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Curves . QuadraticBezier

A quadratic Bézier curve constructed from two control points.

Constructor:

new QuadraticBezier(p0, p1, p2)

Parameters:

name type description
p0 Array.<number> | 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.

Since: 3.2.0

Extends


Members

<private> _tmpVec2A: Phaser.Math.Vector2
Focus
Focus

Description:

A temporary calculation Vector.

Type:
Inherited from: Phaser.Curves.Curve#_tmpVec2A
Since: 3.0.0
Source: src/curves/Curve.js (Line 90)
Focus
Focus
<private> _tmpVec2B: Phaser.Math.Vector2
Focus
Focus

Description:

A temporary calculation Vector.

Type:
Inherited from: Phaser.Curves.Curve#_tmpVec2B
Since: 3.0.0
Source: src/curves/Curve.js (Line 100)
Focus
Focus
active: boolean
Focus
Focus

Description:

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

Type:
boolean
Default: true
Inherited from: Phaser.Curves.Curve#active
Since: 3.0.0
Source: src/curves/Curve.js (Line 80)
Focus
Focus
arcLengthDivisions: number
Focus
Focus

Description:

The quantity of arc length divisions within the curve.

Type:
number
Default: 100
Inherited from: Phaser.Curves.Curve#arcLengthDivisions
Since: 3.0.0
Source: src/curves/Curve.js (Line 50)
Focus
Focus
cacheArcLengths: Array.<number>
Focus
Focus

Description:

An array of cached arc length values.

Type:
Array.<number>
Default: []
Inherited from: Phaser.Curves.Curve#cacheArcLengths
Since: 3.0.0
Source: src/curves/Curve.js (Line 60)
Focus
Focus
defaultDivisions: number
Focus
Focus

Description:

The default number of divisions within the curve.

Type:
number
Default: 5
Inherited from: Phaser.Curves.Curve#defaultDivisions
Since: 3.0.0
Source: src/curves/Curve.js (Line 40)
Focus
Focus
needsUpdate: boolean
Focus
Focus

Description:

Does the data of this curve need updating?

Type:
boolean
Default: true
Inherited from: Phaser.Curves.Curve#needsUpdate
Since: 3.0.0
Source: src/curves/Curve.js (Line 70)
Focus
Focus

Description:

The start point.

Type:
Since: 3.2.0
Focus
Focus

Description:

The first control point.

Type:
Since: 3.2.0
Focus
Focus

Description:

The second control point.

Type:
Since: 3.2.0
Focus
Focus
type: string
Focus
Focus

Description:

String based identifier for the type of curve.

Type:
string
Inherited from: Phaser.Curves.Curve#type
Since: 3.0.0
Source: src/curves/Curve.js (Line 31)
Focus
Focus

Methods

draw(graphics, [pointsTotal])
Focus
Focus

Description:

Draws this curve on the given Graphics object.

The curve is drawn using Graphics.strokePoints so will be drawn at whatever the present Graphics stroke color is. The Graphics object is not cleared before the draw, so the curve will appear on-top of anything else already rendered to it.

Parameters:

name type arguments Default description
graphics Phaser.GameObjects.Graphics

Graphics object to draw onto.

pointsTotal number <optional> 32

Number of points to be used for drawing the curve. Higher numbers result in smoother curve but require more processing.

Returns:
Description:

Graphics object that was drawn to.

Overrides: Phaser.Curves.Curve#draw
Examples:
Since: 3.2.0
Focus
Focus
getBounds([out], [accuracy])
Focus
Focus

Description:

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

Returns:
Description:

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

Inherited from: Phaser.Curves.Curve#getBounds
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 135)
Focus
Focus
getDistancePoints(distance)
Focus
Focus

Description:

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 number

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

Returns:
Description:

An Array of Point objects.

Type:
Inherited from: Phaser.Curves.Curve#getDistancePoints
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 169)
Focus
Focus
getEndPoint([out])
Focus
Focus

Description:

Get a point at the end of the curve.

Parameters:

name type arguments description
out Phaser.Math.Vector2 <optional>

Optional Vector object to store the result in.

Returns:
Description:

Vector2 containing the coordinates of the curves end point.

Inherited from: Phaser.Curves.Curve#getEndPoint
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 189)
Focus
Focus
getLength()
Focus
Focus

Description:

Get total curve arc length

Returns:
Description:

The total length of the curve.

Type:
  • number
Inherited from: Phaser.Curves.Curve#getLength
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 206)
Focus
Focus
getLengths([divisions])
Focus
Focus

Description:

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 arguments description
divisions number <optional>

The number of divisions or segments.

Returns:
Description:

An array of cumulative lengths.

Type:
  • Array.
Inherited from: Phaser.Curves.Curve#getLengths
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 222)
Focus
Focus
getPoint(t, [out])
Focus
Focus

Description:

Get point at relative position in curve according to length.

Parameters:

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.

Returns:
Description:

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

Examples:
Since: 3.2.0
Focus
Focus
getPointAt(u, [out])
Focus
Focus

Description:

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

Parameters:

name type arguments description
u number

The relative position, [0..1].

out Phaser.Math.Vector2 <optional>

A point to store the result in.

Returns:
Description:

The point.

Inherited from: Phaser.Curves.Curve#getPointAt
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 278)
Focus
Focus
getPoints([divisions], [stepRate], [out])
Focus
Focus

Description:

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 arguments description
divisions number <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.

Returns:
Description:

An array of Points from the curve.

Type:
Inherited from: Phaser.Curves.Curve#getPoints
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 300)
Focus
Focus
getRandomPoint([out])
Focus
Focus

Description:

Get a random point from the curve.

Parameters:

name type arguments description
out Phaser.Math.Vector2 <optional>

A point object to store the result in.

Returns:
Description:

The point.

Inherited from: Phaser.Curves.Curve#getRandomPoint
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 349)
Focus
Focus
getResolution(divisions)
Focus
Focus

Description:

Get the resolution of the curve.

Parameters:

name type description
divisions number

Optional divisions value.

Returns:
Description:

The curve resolution.

Type:
  • number
Examples:
Since: 3.2.0
Focus
Focus
getSpacedPoints([divisions], [stepRate], [out])
Focus
Focus

Description:

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

1 + divisions points will be returned.

Parameters:

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.

Returns:
Description:

An array of points.

Type:
Inherited from: Phaser.Curves.Curve#getSpacedPoints
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 370)
Focus
Focus
getStartPoint([out])
Focus
Focus

Description:

Gets the starting point on the curve.

Parameters:

name type arguments description
out Phaser.Math.Vector2 <optional>

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

Returns:
Description:

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

Overrides: Phaser.Curves.Curve#getStartPoint
Examples:
Since: 3.2.0
Focus
Focus
getTFromDistance(distance, [divisions])
Focus
Focus

Description:

Given a distance in pixels, get a t to find p.

Parameters:

name type arguments description
distance number

The distance, in pixels.

divisions number <optional>

Optional amount of divisions.

Returns:
Description:

The distance.

Type:
  • number
Inherited from: Phaser.Curves.Curve#getTFromDistance
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 492)
Focus
Focus
getTangent(t, [out])
Focus
Focus

Description:

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 arguments description
t number

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

out Phaser.Math.Vector2 <optional>

A vector to store the result in.

Returns:
Description:

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

Inherited from: Phaser.Curves.Curve#getTangent
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 430)
Focus
Focus
getTangentAt(u, [out])
Focus
Focus

Description:

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

Parameters:

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.

Returns:
Description:

The tangent vector.

Inherited from: Phaser.Curves.Curve#getTangentAt
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 472)
Focus
Focus
getUtoTmapping(u, distance, [divisions])
Focus
Focus

Description:

Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant.

Parameters:

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.

Returns:
Description:

The equidistant value.

Type:
  • number
Inherited from: Phaser.Curves.Curve#getUtoTmapping
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 513)
Focus
Focus
toJSON()
Focus
Focus

Description:

Converts the curve into a JSON compatible object.

Returns:
Description:

The JSON object containing this curve data.

Examples:
Since: 3.2.0
Focus
Focus
updateArcLengths()
Focus
Focus

Description:

Calculate and cache the arc lengths.

Inherited from: Phaser.Curves.Curve#updateArcLengths
Examples:
Since: 3.0.0
Source: src/curves/Curve.js (Line 594)
Focus
Focus
<static> fromJSON(data)
Focus
Focus

Description:

Creates a curve from a JSON object, e. g. created by toJSON.

Parameters:

name type description
data Phaser.Types.Curves.JSONCurve

The JSON object containing this curve data.

Returns:
Description:

The created curve instance.

Examples:
Since: 3.2.0
Focus
Focus