Class: Line

Phaser.Curves. Line

A LineCurve is a "curve" comprising exactly two points (a line segment).


new Line(p0 [, p1])

Parameters:
Name Type Argument Description
p0 Phaser.Math.Vector2 | Array.<number>

The first endpoint.

p1 Phaser.Math.Vector2 <optional>

The second endpoint.

Since: 3.0.0
Source: src/curves/LineCurve.js (Line 17)

Extends

Members


active :boolean

[description]

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

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

p1 :Phaser.Math.Vector2

The second endpoint.

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

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)

Configures this line from a JSON representation.

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

The JSON object containing this curve data.

Since: 3.0.0
Source: src/curves/LineCurve.js (Line 231)
Returns:

A new LineCurve object.

Type
Phaser.Curves.Line

draw(graphics)

Draws this curve on the given Graphics object.

The curve is drawn using Graphics.lineBetween so will be drawn at whatever the present Graphics line 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 Description
graphics Phaser.GameObjects.Graphics

The Graphics instance onto which this curve will be drawn.

Since: 3.0.0
Overrides:
Source: src/curves/LineCurve.js (Line 187)
Returns:

The Graphics object to which the curve was drawn.

Type
Phaser.GameObjects.Graphics

getBounds( [out])

Returns a Rectangle where the position and dimensions match the bounds of this Curve.

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

A Rectangle object to store the bounds in. If not given a new Rectangle will be created.

Since: 3.0.0
Overrides:
Source: src/curves/LineCurve.js (Line 66)
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])

[description]

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:

[description]

Type
number

getLengths( [divisions])

Get list of cumulative segment lengths

Parameters:
Name Type Argument Description
divisions integer <optional>

[description]

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

[description]

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/LineCurve.js (Line 121)
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])

Gets a point at a given position on the line.

Parameters:
Name Type Argument Description
u 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
Overrides:
Source: src/curves/LineCurve.js (Line 150)
Returns:

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

Type
Phaser.Math.Vector2

getPoints( [divisions])

[description]

Parameters:
Name Type Argument Description
divisions integer <optional>

[description]

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

[description]

Type
Phaser.Math.Vector2

getResolution( [divisions])

Gets the resolution of the line.

Parameters:
Name Type Argument Default Description
divisions number <optional>
1

The number of divisions to consider.

Since: 3.0.0
Source: src/curves/LineCurve.js (Line 104)
Returns:

The resolution. Equal to the number of divisions.

Type
number

getSpacedPoints( [divisions])

[description]

Parameters:
Name Type Argument Description
divisions integer <optional>

[description]

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

[description]

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/LineCurve.js (Line 85)
Returns:

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

Type
Phaser.Math.Vector2

getTangent()

Gets the slope of the line as a unit vector.

Since: 3.0.0
Overrides:
Source: src/curves/LineCurve.js (Line 168)
Returns:

The tangent vector.

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

[description]

Type
number

toJSON()

Gets a JSON representation of the line.

Since: 3.0.0
Source: src/curves/LineCurve.js (Line 210)
Returns:

The JSON object containing this curve data.

Type
Phaser.Types.Curves.JSONCurve

updateArcLengths()

[description]

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