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 13)

Members


bottom :number

The bottom position of the Line.

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

left :number

The left position of the Line.

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

The right position of the Line.

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

top :number

The top position of the Line.

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

x1 :number

The x coordinate of the lines starting point.

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

x2 :number

The x coordinate of the lines ending point.

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

y1 :number

The y coordinate of the lines starting point.

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

y2 :number

The y coordinate of the lines ending point.

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

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 integer <optional>
1

The optional step rate for the points on the line.

results array <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.<object>

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

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

[description]

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:

[description]

Type
number

<static> NormalY(line)

[description]

Parameters:
Name Type Description
line Phaser.Geom.Line

[description]

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

[description]

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 75)
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 163)
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 184)
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 integer

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

stepRate integer <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 93)
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 117)
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 134)
Returns:

This Line object.

Type
Phaser.Geom.Line