Class: Curve

Phaser.Curves. Curve

A Base Curve class, which all other curve types extend.

Based on the three.js Curve classes created by zz85


new Curve(type)

Parameters:
Name Type Description
type string

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 12)

Members


active :boolean

[description]

Type:
  • boolean
Since: 3.0.0
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
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
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
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
Default Value:
  • true
Source: src/curves/Curve.js (Line 70)

type :string

String based identifier for the type of curve.

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

Methods


draw(graphics [, pointsTotal])

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 Argument Default Description
graphics Phaser.GameObjects.Graphics

The Graphics instance onto which this curve will be drawn.

pointsTotal integer <optional>
32

The resolution of the curve. The higher the value the smoother it will render, at the cost of rendering performance.

Since: 3.0.0
Source: src/curves/Curve.js (Line 111)
Returns:

The Graphics object to which the curve was drawn.

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
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
Source: src/curves/Curve.js (Line 169)
Returns:

An Array of Point objects.

Type
Array.<Phaser.Geom.Point>

getEndPoint( [out])

[description]

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

Optional Vector object to store the result in.

Since: 3.0.0
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
Source: src/curves/Curve.js (Line 206)
Returns:

[description]

Type
number

getLengths( [divisions])

Get list of cumulative segment lengths

Parameters:
Name Type Argument Description
divisions integer <optional>

[description]

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

[description]

Type
Array.<number>

getPointAt(u [, out])

[description]

Parameters:
Name Type Argument Description
u number

[description]

out Phaser.Math.Vector2 <optional>

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 270)
Returns:

[description]

Type
Phaser.Math.Vector2

getPoints( [divisions])

[description]

Parameters:
Name Type Argument Description
divisions integer <optional>

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 292)
Returns:

[description]

Type
Array.<Phaser.Math.Vector2>

getRandomPoint( [out])

[description]

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

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 316)
Returns:

[description]

Type
Phaser.Math.Vector2

getSpacedPoints( [divisions])

[description]

Parameters:
Name Type Argument Description
divisions integer <optional>

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 337)
Returns:

[description]

Type
Array.<Phaser.Math.Vector2>

getStartPoint( [out])

[description]

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

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 363)
Returns:

[description]

Type
Phaser.Math.Vector2

getTangent(t [, out])

Returns a unit vector tangent at t 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

[description]

out Phaser.Math.Vector2 <optional>

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 382)
Returns:

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

Type
Phaser.Math.Vector2

getTangentAt(u [, out])

[description]

Parameters:
Name Type Argument Description
u number

[description]

out Phaser.Math.Vector2 <optional>

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 424)
Returns:

[description]

Type
Phaser.Math.Vector2

getTFromDistance(distance [, divisions])

[description]

Parameters:
Name Type Argument Description
distance integer

[description]

divisions integer <optional>

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 445)
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
Source: src/curves/Curve.js (Line 468)
Returns:

[description]

Type
number

updateArcLengths()

[description]

Since: 3.0.0
Source: src/curves/Curve.js (Line 549)