Phaser API Documentation

  Version: 
Filter

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

Constructor:

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

Parameters:

name type arguments description
x1 number <optional>

The x coordinate of the lines starting point.

y1 number <optional>

The y coordinate of the lines starting point.

x2 number <optional>

The x coordinate of the lines ending point.

y2 number <optional>

The y coordinate of the lines ending point.

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

Members

bottom: number
Focus
Focus

Description:

The bottom position of the Line.

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

Description:

The left position of the Line.

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

Description:

The top position of the Line.

Type:
number
Since: 3.0.0
Source: src/geom/line/Line.js (Line 273)
Focus
Focus
<readonly> type: number
Focus
Focus

Description:

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)
Focus
Focus
x1: number
Focus
Focus

Description:

The x coordinate of the lines starting point.

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

Description:

The x coordinate of the lines ending point.

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

Description:

The y coordinate of the lines starting point.

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

Description:

The y coordinate of the lines ending point.

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

Methods

getPoint(position, [output])
Focus
Focus

Description:

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

Parameters:

name type arguments 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 object | Phaser.Geom.Point <optional>

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

Returns:
Description:

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

Type:
Since: 3.0.0
Source: src/geom/line/Line.js (Line 87)
Focus
Focus
getPointA([vec2])
Focus
Focus

Description:

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

Parameters:

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

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

Returns:
Description:

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

Since: 3.0.0
Source: src/geom/line/Line.js (Line 175)
Focus
Focus
getPointB([vec2])
Focus
Focus

Description:

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

Parameters:

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

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

Returns:
Description:

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

Since: 3.0.0
Source: src/geom/line/Line.js (Line 196)
Focus
Focus
getPoints(quantity, [stepRate], [output])
Focus
Focus

Description:

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

Returns:
Description:

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

Type:
Since: 3.0.0
Source: src/geom/line/Line.js (Line 105)
Focus
Focus
getRandomPoint([point])
Focus
Focus

Description:

Get a random Point on the Line.

Parameters:

name type arguments description
point object | Phaser.Geom.Point <optional>

An instance of a Point to be modified.

Returns:
Description:

A random Point on the Line.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 129)
Focus
Focus
setTo([x1], [y1], [x2], [y2])
Focus
Focus

Description:

Set new coordinates for the line endpoints.

Parameters:

name type arguments description
x1 number <optional>

The x coordinate of the lines starting point.

y1 number <optional>

The y coordinate of the lines starting point.

x2 number <optional>

The x coordinate of the lines ending point.

y2 number <optional>

The y coordinate of the lines ending point.

Returns:
Description:

This Line object.

Since: 3.0.0
Source: src/geom/line/Line.js (Line 146)
Focus
Focus
<static> Angle(line)
Focus
Focus

Description:

Calculate the angle of the line in radians.

Parameters:

name type description
line Phaser.Geom.Line

The line to calculate the angle of.

Returns:
Description:

The angle of the line, in radians.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Angle.js (Line 7)
Focus
Focus
<static> BresenhamPoints(line, [stepRate], [results])
Focus
Focus

Description:

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

Returns:
Description:

The array of coordinates on the line.

Since: 3.0.0
Focus
Focus
<static> CenterOn(line, x, y)
Focus
Focus

Description:

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.

Returns:
Description:

The centered line.

Since: 3.0.0
Source: src/geom/line/CenterOn.js (Line 8)
Focus
Focus
<static> Clone(source)
Focus
Focus

Description:

Clone the given line.

Parameters:

name type description
source Phaser.Geom.Line

The source line to clone.

Returns:
Description:

The cloned line.

Since: 3.0.0
Source: src/geom/line/Clone.js (Line 9)
Focus
Focus
<static> CopyFrom(source, dest)
Focus
Focus

Description:

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.

Returns:
Description:

The destination line.

Since: 3.0.0
Source: src/geom/line/CopyFrom.js (Line 7)
Focus
Focus
<static> Equals(line, toCompare)
Focus
Focus

Description:

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.

Returns:
Description:

Whether the two lines are equal.

Type:
  • boolean
Since: 3.0.0
Source: src/geom/line/Equals.js (Line 7)
Focus
Focus
<static> Extend(line, left, [right])
Focus
Focus

Description:

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

Returns:
Description:

The modified Line instance.

Since: 3.16.0
Source: src/geom/line/Extend.js (Line 9)
Focus
Focus
<static> GetEasedPoints(line, ease, quantity, [collinearThreshold], [easeParams])
Focus
Focus

Description:

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

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.

Returns:
Description:

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

Type:
Since: 3.23.0
Focus
Focus
<static> GetMidPoint(line, [out])
Focus
Focus

Description:

Get the midpoint of the given line.

Parameters:

name type arguments description
line Phaser.Geom.Line

The line to get the midpoint of.

out object | Phaser.Geom.Point <optional>

An optional point object to store the midpoint in.

Returns:
Description:

The midpoint of the Line.

Type:
Since: 3.0.0
Focus
Focus
<static> GetNearestPoint(line, point, [out])
Focus
Focus

Description:

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

Parameters:

name type arguments description
line Phaser.Geom.Line

The line to get the nearest point on.

point object | Phaser.Geom.Point

The point to get the nearest point to.

out object | Phaser.Geom.Point <optional>

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

Returns:
Description:

The nearest point on the line.

Type:
Since: 3.16.0
Focus
Focus
<static> GetNormal(line, [out])
Focus
Focus

Description:

Calculate the normal of the given line.

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

Parameters:

name type arguments description
line Phaser.Geom.Line

The line to calculate the normal of.

out object | Phaser.Geom.Point <optional>

An optional point object to store the normal in.

Returns:
Description:

The normal of the Line.

Type:
Since: 3.0.0
Focus
Focus
<static> GetPoint(line, position, [out])
Focus
Focus

Description:

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

Parameters:

name type arguments 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 object | Phaser.Geom.Point <optional>

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

Returns:
Description:

The point on the line.

Type:
Since: 3.0.0
Source: src/geom/line/GetPoint.js (Line 9)
Focus
Focus
<static> GetPoints(line, quantity, [stepRate], [out])
Focus
Focus

Description:

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

Returns:
Description:

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

Type:
Since: 3.0.0
Focus
Focus
<static> GetShortestDistance(line, point)
Focus
Focus

Description:

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 object | Phaser.Geom.Point

The point to get the shortest distance to.

Returns:
Description:

The shortest distance from the line to the point.

Type:
  • number
Since: 3.16.0
Focus
Focus
<static> Height(line)
Focus
Focus

Description:

Calculate the height of the given line.

Parameters:

name type description
line Phaser.Geom.Line

The line to calculate the height of.

Returns:
Description:

The height of the line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Height.js (Line 7)
Focus
Focus
<static> Length(line)
Focus
Focus

Description:

Calculate the length of the given line.

Parameters:

name type description
line Phaser.Geom.Line

The line to calculate the length of.

Returns:
Description:

The length of the line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Length.js (Line 7)
Focus
Focus
<static> NormalAngle(line)
Focus
Focus

Description:

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.

Returns:
Description:

The angle of the normal of the line in radians.

Type:
  • number
Since: 3.0.0
Focus
Focus
<static> NormalX(line)
Focus
Focus

Description:

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.

Returns:
Description:

The x component of the normal vector of the line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/NormalX.js (Line 10)
Focus
Focus
<static> NormalY(line)
Focus
Focus

Description:

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.

Returns:
Description:

The Y value of the normal of the Line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/NormalY.js (Line 10)
Focus
Focus
<static> Offset(line, x, y)
Focus
Focus

Description:

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.

Returns:
Description:

The offset line.

Since: 3.0.0
Source: src/geom/line/Offset.js (Line 7)
Focus
Focus
<static> PerpSlope(line)
Focus
Focus

Description:

Calculate the perpendicular slope of the given line.

Parameters:

name type description
line Phaser.Geom.Line

The line to calculate the perpendicular slope of.

Returns:
Description:

The perpendicular slope of the line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/PerpSlope.js (Line 7)
Focus
Focus
<static> Random(line, [out])
Focus
Focus

Description:

Returns a random point on a given Line.

Parameters:

name type arguments description
line Phaser.Geom.Line

The Line to calculate the random Point on.

out object | Phaser.Geom.Point <optional>

An instance of a Point to be modified.

Returns:
Description:

A random Point on the Line.

Type:
Since: 3.0.0
Source: src/geom/line/Random.js (Line 9)
Focus
Focus
<static> ReflectAngle(lineA, lineB)
Focus
Focus

Description:

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.

Returns:
Description:

The reflected angle between each line.

Type:
  • number
Since: 3.0.0
Focus
Focus
<static> Rotate(line, angle)
Focus
Focus

Description:

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.

Returns:
Description:

The rotated line.

Since: 3.0.0
Source: src/geom/line/Rotate.js (Line 9)
Focus
Focus
<static> RotateAroundPoint(line, point, angle)
Focus
Focus

Description:

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 object | Phaser.Geom.Point

The point to rotate the line around.

angle number

The angle of rotation in radians.

Returns:
Description:

The rotated line.

Since: 3.0.0
Focus
Focus
<static> RotateAroundXY(line, x, y, angle)
Focus
Focus

Description:

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.

Returns:
Description:

The rotated line.

Since: 3.0.0
Focus
Focus
<static> SetToAngle(line, x, y, angle, length)
Focus
Focus

Description:

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.

Returns:
Description:

The updated line.

Since: 3.0.0
Focus
Focus
<static> Slope(line)
Focus
Focus

Description:

Calculate the slope of the given line.

Parameters:

name type description
line Phaser.Geom.Line

The line to calculate the slope of.

Returns:
Description:

The slope of the line.

Type:
  • number
Since: 3.0.0
Source: src/geom/line/Slope.js (Line 7)
Focus
Focus
<static> Width(line)
Focus
Focus

Description:

Calculate the width of the given line.

Parameters:

name type description
line Phaser.Geom.Line

The line to calculate the width of.

Returns:
Description:

The width of the line.

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