Class: Line

Phaser.Geom. Line

Defines a Line segment, a part of a line between two endpoints.


new Line( [x1] [, y1] [, x2] [, y2])

Parameters:
Name Type Argument Default Description
x1 number <optional>
0

The x coordinate of the lines starting point.

y1 number <optional>
0

The y coordinate of the lines starting point.

x2 number <optional>
0

The x coordinate of the lines ending point.

y2 number <optional>
0

The y coordinate of the lines ending point.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 14)

Members


bottom :number

The bottom position of the Line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 301)

left :number

The left position of the Line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 217)

The right position of the Line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 245)

top :number

The top position of the Line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 273)

<readonly> type :number

The geometry constant type of this object: GEOM_CONST.LINE. Used for fast type comparisons.

Type:
  • number
Since: 3.19.0
Source: src/geom/line/Line.js (Line 39)

x1 :number

The x coordinate of the lines starting point.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 50)

x2 :number

The x coordinate of the lines ending point.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 68)

y1 :number

The y coordinate of the lines starting point.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 59)

y2 :number

The y coordinate of the lines ending point.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 77)

Methods


<static> Angle(line)

Calculate the angle of the line in radians.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the angle of.

Since: 3.0.0
Source: src/geom/line/Angle.js (Line 7)
Returns:

The angle of the line, in radians.

Type
number

<static> BresenhamPoints(line [, stepRate] [, results])

Using Bresenham's line algorithm this will return an array of all coordinates on this line.

The start and end points are rounded before this runs as the algorithm works on integers.

Parameters:
Name Type Argument Default Description
line Phaser.Geom.Line

The line.

stepRate number <optional>
1

The optional step rate for the points on the line.

results Array.<Phaser.Types.Math.Vector2Like> <optional>

An optional array to push the resulting coordinates into.

Since: 3.0.0
Source: src/geom/line/BresenhamPoints.js (Line 7)
Returns:

The array of coordinates on the line.

Type
Array.<Phaser.Types.Math.Vector2Like>

<static> CenterOn(line, x, y)

Center a line on the given coordinates.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to center.

x number

The horizontal coordinate to center the line on.

y number

The vertical coordinate to center the line on.

Since: 3.0.0
Source: src/geom/line/CenterOn.js (Line 8)
Returns:

The centered line.

Type
Phaser.Geom.Line

<static> Clone(source)

Clone the given line.

Parameters:
Name Type Description
source Phaser.Geom.Line

The source line to clone.

Since: 3.0.0
Source: src/geom/line/Clone.js (Line 9)
Returns:

The cloned line.

Type
Phaser.Geom.Line

<static> CopyFrom(source, dest)

Copy the values of one line to a destination line.

Parameters:
Name Type Description
source Phaser.Geom.Line

The source line to copy the values from.

dest Phaser.Geom.Line

The destination line to copy the values to.

Since: 3.0.0
Source: src/geom/line/CopyFrom.js (Line 7)
Returns:

The destination line.

Type
Phaser.Geom.Line

<static> Equals(line, toCompare)

Compare two lines for strict equality.

Parameters:
Name Type Description
line Phaser.Geom.Line

The first line to compare.

toCompare Phaser.Geom.Line

The second line to compare.

Since: 3.0.0
Source: src/geom/line/Equals.js (Line 7)
Returns:

Whether the two lines are equal.

Type
boolean

<static> Extend(line, left [, right])

Extends the start and end points of a Line by the given amounts.

The amounts can be positive or negative. Positive points will increase the length of the line, while negative ones will decrease it.

If no right value is provided it will extend the length of the line equally in both directions.

Pass a value of zero to leave the start or end point unchanged.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line instance to extend.

left number

The amount to extend the start of the line by.

right number <optional>

The amount to extend the end of the line by. If not given it will be set to the left value.

Since: 3.16.0
Source: src/geom/line/Extend.js (Line 9)
Returns:

The modified Line instance.

Type
Phaser.Geom.Line

<static> GetEasedPoints(line, ease, quantity [, collinearThreshold] [, easeParams])

Returns an array of quantity Points where each point is taken from the given Line, spaced out according to the ease function specified.

const line = new Phaser.Geom.Line(100, 300, 700, 300);
const points = Phaser.Geom.Line.GetEasedPoints(line, 'sine.out', 32)

In the above example, the points array will contain 32 points spread-out across the length of line, where the position of each point is determined by the Sine.out ease function.

You can optionally provide a collinear threshold. In this case, the resulting points are checked against each other, and if they are < collinearThreshold distance apart, they are dropped from the results. This can help avoid lots of clustered points at far ends of the line with tightly-packed eases such as Quartic. Leave the value set to zero to skip this check.

Note that if you provide a collinear threshold, the resulting array may not always contain quantity points.

Parameters:
Name Type Argument Default Description
line Phaser.Geom.Line

The Line object.

ease string | function

The ease to use. This can be either a string from the EaseMap, or a custom function.

quantity number

The number of points to return. Note that if you provide a collinearThreshold, the resulting array may not always contain this number of points.

collinearThreshold number <optional>
0

An optional threshold. The final array is reduced so that each point is spaced out at least this distance apart. This helps reduce clustering in noisey eases.

easeParams Array.<number> <optional>

An optional array of ease parameters to go with the ease.

Since: 3.23.0
Source: src/geom/line/GetEasedPoints.js (Line 11)
Returns:

An array of Geom.Points containing the coordinates of the points on the line.

Type
Array.<Phaser.Geom.Point>

<static> GetMidPoint(line [, out])

Get the midpoint of the given line.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line to get the midpoint of.

out Phaser.Geom.Point | object <optional>

An optional point object to store the midpoint in.

Since: 3.0.0
Source: src/geom/line/GetMidPoint.js (Line 9)
Returns:

The midpoint of the Line.

Type
Phaser.Geom.Point | object

<static> GetNearestPoint(line, point [, out])

Get the nearest point on a line perpendicular to the given point.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line to get the nearest point on.

point Phaser.Geom.Point | object

The point to get the nearest point to.

out Phaser.Geom.Point | object <optional>

An optional point, or point-like object, to store the coordinates of the nearest point on the line.

Since: 3.16.0
Source: src/geom/line/GetNearestPoint.js (Line 10)
Returns:

The nearest point on the line.

Type
Phaser.Geom.Point | object

<static> GetNormal(line [, out])

Calculate the normal of the given line.

The normal of a line is a vector that points perpendicular from it.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line to calculate the normal of.

out Phaser.Geom.Point | object <optional>

An optional point object to store the normal in.

Since: 3.0.0
Source: src/geom/line/GetNormal.js (Line 11)
Returns:

The normal of the Line.

Type
Phaser.Geom.Point | object

<static> GetPoint(line, position [, out])

Get a point on a line that's a given percentage along its length.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line.

position number

A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.

out Phaser.Geom.Point | object <optional>

An optional point, or point-like object, to store the coordinates of the point on the line.

Since: 3.0.0
Source: src/geom/line/GetPoint.js (Line 9)
Returns:

The point on the line.

Type
Phaser.Geom.Point | object

<static> GetPoints(line, quantity [, stepRate] [, out])

Get a number of points along a line's length.

Provide a quantity to get an exact number of points along the line.

Provide a stepRate to ensure a specific distance between each point on the line. Set quantity to 0 when providing a stepRate.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line.

quantity number

The number of points to place on the line. Set to 0 to use stepRate instead.

stepRate number <optional>

The distance between each point on the line. When set, quantity is implied and should be set to 0.

out array | Array.<Phaser.Geom.Point> <optional>

An optional array of Points, or point-like objects, to store the coordinates of the points on the line.

Since: 3.0.0
Source: src/geom/line/GetPoints.js (Line 10)
Returns:

An array of Points, or point-like objects, containing the coordinates of the points on the line.

Type
array | Array.<Phaser.Geom.Point>

<static> GetShortestDistance(line, point)

Get the shortest distance from a Line to the given Point.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to get the distance from.

point Phaser.Geom.Point | object

The point to get the shortest distance to.

Since: 3.16.0
Source: src/geom/line/GetShortestDistance.js (Line 8)
Returns:

The shortest distance from the line to the point.

Type
number

<static> Height(line)

Calculate the height of the given line.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the height of.

Since: 3.0.0
Source: src/geom/line/Height.js (Line 7)
Returns:

The height of the line.

Type
number

<static> Length(line)

Calculate the length of the given line.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the length of.

Since: 3.0.0
Source: src/geom/line/Length.js (Line 7)
Returns:

The length of the line.

Type
number

<static> NormalAngle(line)

Get the angle of the normal of the given line in radians.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the angle of the normal of.

Since: 3.0.0
Source: src/geom/line/NormalAngle.js (Line 11)
Returns:

The angle of the normal of the line in radians.

Type
number

<static> NormalX(line)

Returns the x component of the normal vector of the given line.

Parameters:
Name Type Description
line Phaser.Geom.Line

The Line object to get the normal value from.

Since: 3.0.0
Source: src/geom/line/NormalX.js (Line 10)
Returns:

The x component of the normal vector of the line.

Type
number

<static> NormalY(line)

The Y value of the normal of the given line. The normal of a line is a vector that points perpendicular from it.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the normal of.

Since: 3.0.0
Source: src/geom/line/NormalY.js (Line 10)
Returns:

The Y value of the normal of the Line.

Type
number

<static> Offset(line, x, y)

Offset a line by the given amount.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to offset.

x number

The horizontal offset to add to the line.

y number

The vertical offset to add to the line.

Since: 3.0.0
Source: src/geom/line/Offset.js (Line 7)
Returns:

The offset line.

Type
Phaser.Geom.Line

<static> PerpSlope(line)

Calculate the perpendicular slope of the given line.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the perpendicular slope of.

Since: 3.0.0
Source: src/geom/line/PerpSlope.js (Line 7)
Returns:

The perpendicular slope of the line.

Type
number

<static> Random(line [, out])

Returns a random point on a given Line.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The Line to calculate the random Point on.

out Phaser.Geom.Point | object <optional>

An instance of a Point to be modified.

Since: 3.0.0
Source: src/geom/line/Random.js (Line 9)
Returns:

A random Point on the Line.

Type
Phaser.Geom.Point | object

<static> ReflectAngle(lineA, lineB)

Calculate the reflected angle between two lines.

This is the outgoing angle based on the angle of Line 1 and the normalAngle of Line 2.

Parameters:
Name Type Description
lineA Phaser.Geom.Line

The first line.

lineB Phaser.Geom.Line

The second line.

Since: 3.0.0
Source: src/geom/line/ReflectAngle.js (Line 10)
Returns:

The reflected angle between each line.

Type
number

<static> Rotate(line, angle)

Rotate a line around its midpoint by the given angle in radians.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to rotate.

angle number

The angle of rotation in radians.

Since: 3.0.0
Source: src/geom/line/Rotate.js (Line 9)
Returns:

The rotated line.

Type
Phaser.Geom.Line

<static> RotateAroundPoint(line, point, angle)

Rotate a line around a point by the given angle in radians.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to rotate.

point Phaser.Geom.Point | object

The point to rotate the line around.

angle number

The angle of rotation in radians.

Since: 3.0.0
Source: src/geom/line/RotateAroundPoint.js (Line 9)
Returns:

The rotated line.

Type
Phaser.Geom.Line

<static> RotateAroundXY(line, x, y, angle)

Rotate a line around the given coordinates by the given angle in radians.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to rotate.

x number

The horizontal coordinate to rotate the line around.

y number

The vertical coordinate to rotate the line around.

angle number

The angle of rotation in radians.

Since: 3.0.0
Source: src/geom/line/RotateAroundXY.js (Line 7)
Returns:

The rotated line.

Type
Phaser.Geom.Line

<static> SetToAngle(line, x, y, angle, length)

Set a line to a given position, angle and length.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to set.

x number

The horizontal start position of the line.

y number

The vertical start position of the line.

angle number

The angle of the line in radians.

length number

The length of the line.

Since: 3.0.0
Source: src/geom/line/SetToAngle.js (Line 7)
Returns:

The updated line.

Type
Phaser.Geom.Line

<static> Slope(line)

Calculate the slope of the given line.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the slope of.

Since: 3.0.0
Source: src/geom/line/Slope.js (Line 7)
Returns:

The slope of the line.

Type
number

<static> Width(line)

Calculate the width of the given line.

Parameters:
Name Type Description
line Phaser.Geom.Line

The line to calculate the width of.

Since: 3.0.0
Source: src/geom/line/Width.js (Line 7)
Returns:

The width of the line.

Type
number

getPoint(position [, output])

Get a point on a line that's a given percentage along its length.

Parameters:
Name Type Argument Description
position number

A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.

output Phaser.Geom.Point | object <optional>

An optional point, or point-like object, to store the coordinates of the point on the line.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 87)
Returns:

A Point, or point-like object, containing the coordinates of the point on the line.

Type
Phaser.Geom.Point | object

getPointA( [vec2])

Returns a Vector2 object that corresponds to the start of this Line.

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

A Vector2 object to set the results in. If undefined a new Vector2 will be created.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 175)
Returns:

A Vector2 object that corresponds to the start of this Line.

Type
Phaser.Math.Vector2

getPointB( [vec2])

Returns a Vector2 object that corresponds to the end of this Line.

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

A Vector2 object to set the results in. If undefined a new Vector2 will be created.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 196)
Returns:

A Vector2 object that corresponds to the end of this Line.

Type
Phaser.Math.Vector2

getPoints(quantity [, stepRate] [, output])

Get a number of points along a line's length.

Provide a quantity to get an exact number of points along the line.

Provide a stepRate to ensure a specific distance between each point on the line. Set quantity to 0 when providing a stepRate.

Parameters:
Name Type Argument Description
quantity number

The number of points to place on the line. Set to 0 to use stepRate instead.

stepRate number <optional>

The distance between each point on the line. When set, quantity is implied and should be set to 0.

output array | Array.<Phaser.Geom.Point> <optional>

An optional array of Points, or point-like objects, to store the coordinates of the points on the line.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 105)
Returns:

An array of Points, or point-like objects, containing the coordinates of the points on the line.

Type
array | Array.<Phaser.Geom.Point>

getRandomPoint( [point])

Get a random Point on the Line.

Parameters:
Name Type Argument Description
point Phaser.Geom.Point | object <optional>

An instance of a Point to be modified.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 129)
Returns:

A random Point on the Line.

Type
Phaser.Geom.Point

setTo( [x1] [, y1] [, x2] [, y2])

Set new coordinates for the line endpoints.

Parameters:
Name Type Argument Default Description
x1 number <optional>
0

The x coordinate of the lines starting point.

y1 number <optional>
0

The y coordinate of the lines starting point.

x2 number <optional>
0

The x coordinate of the lines ending point.

y2 number <optional>
0

The y coordinate of the lines ending point.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 146)
Returns:

This Line object.

Type
Phaser.Geom.Line