Skip to main content
Version: Phaser v4.0.0-rc.6

Line

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

Constructor

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

Parameters

nametypeoptionaldefaultdescription
x1numberYes0The x coordinate of the lines starting point.
y1numberYes0The y coordinate of the lines starting point.
x2numberYes0The x coordinate of the lines ending point.
y2numberYes0The y coordinate of the lines ending point.

Scope: static

Source: src/geom/line/Line.js#L14
Since: 3.0.0

Public Methods

Angle

<static> Angle(line)

Description:

Calculate the angle of the line in radians.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the angle of.

Returns: number - The angle of the line, in radians.

Source: src/geom/line/Angle.js#L7
Since: 3.0.0


BresenhamPoints

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

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:

nametypeoptionaldefaultdescription
linePhaser.Geom.LineNoThe line.
stepRatenumberYes1The optional step rate for the points on the line.
resultsArray.<Phaser.Types.Math.Vector2Like>YesAn optional array to push the resulting coordinates into.

Returns: Array.<Phaser.Types.Math.Vector2Like> - The array of coordinates on the line.

Source: src/geom/line/BresenhamPoints.js#L7
Since: 3.0.0


CenterOn

<static> CenterOn(line, x, y)

Description:

Center a line on the given coordinates.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to center.
xnumberNoThe horizontal coordinate to center the line on.
ynumberNoThe vertical coordinate to center the line on.

Returns: Phaser.Geom.Line - The centered line.

Source: src/geom/line/CenterOn.js#L8
Since: 3.0.0


Clone

<static> Clone(source)

Description:

Clone the given line.

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.LineNoThe source line to clone.

Returns: Phaser.Geom.Line - The cloned line.

Source: src/geom/line/Clone.js#L9
Since: 3.0.0


CopyFrom

<static> CopyFrom(source, dest)

Description:

Copy the values of one line to a destination line.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.LineNoThe source line to copy the values from.
destPhaser.Geom.LineNoThe destination line to copy the values to.

Returns: Phaser.Geom.Line - The destination line.

Source: src/geom/line/CopyFrom.js#L7
Since: 3.0.0


Equals

<static> Equals(line, toCompare)

Description:

Compare two lines for strict equality.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe first line to compare.
toComparePhaser.Geom.LineNoThe second line to compare.

Returns: boolean - Whether the two lines are equal.

Source: src/geom/line/Equals.js#L7
Since: 3.0.0


Extend

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

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:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line instance to extend.
leftnumberNoThe amount to extend the start of the line by.
rightnumberYesThe amount to extend the end of the line by. If not given it will be set to the left value.

Returns: Phaser.Geom.Line - The modified Line instance.

Source: src/geom/line/Extend.js#L9
Since: 3.16.0


GetEasedPoints

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

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.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
linePhaser.Geom.LineNoThe Line object.
easestring | functionNoThe ease to use. This can be either a string from the EaseMap, or a custom function.
quantitynumberNoThe number of points to return. Note that if you provide a collinearThreshold, the resulting array may not always contain this number of points.
collinearThresholdnumberYes0An 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.
easeParamsArray.<number>YesAn optional array of ease parameters to go with the ease.

Returns: Array.<Phaser.Math.Vector2> - An array of Math.Vector2s containing the coordinates of the points on the line.

Source: src/geom/line/GetEasedPoints.js#L11
Since: 3.23.0


GetMidPoint

<static> GetMidPoint(line, [out])

Description:

Get the midpoint of the given line.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to get the midpoint of.
outPhaser.Math.Vector2YesAn optional Vector2 object to store the midpoint in.

Returns: Phaser.Math.Vector2 - The midpoint of the Line.

Source: src/geom/line/GetMidPoint.js#L9
Since: 3.0.0


GetNearestPoint

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

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to get the nearest point on.
vecPhaser.Math.Vector2NoThe Vector2 to get the nearest point to.
outPhaser.Math.Vector2YesAn optional Vector2 object, to store the coordinates of the nearest point on the line.

Returns: Phaser.Math.Vector2 - The nearest point on the line.

Source: src/geom/line/GetNearestPoint.js#L10
Since: 3.16.0


GetNormal

<static> GetNormal(line, [out])

Description:

Calculate the normal of the given line.

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the normal of.
outPhaser.Math.Vector2YesAn optional Vector2 object to store the normal in.

Returns: Phaser.Math.Vector2 - The normal of the Line.

Source: src/geom/line/GetNormal.js#L11
Since: 3.0.0


getPoint

<instance> getPoint(position, [output])

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
positionnumberNoA value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.
outputPhaser.Math.Vector2YesAn optional Vector2 object to store the coordinates of the point on the line.

Returns: Phaser.Math.Vector2 - A Vector2 object containing the coordinates of the point on the line.

Source: src/geom/line/Line.js#L87
Since: 3.0.0


GetPoint

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

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line.
positionnumberNoA value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.
outPhaser.Math.Vector2YesAn optional Vector2 object to store the coordinates of the point on the line.

Returns: Phaser.Math.Vector2 - The point on the line.

Source: src/geom/line/GetPoint.js#L9
Since: 3.0.0


getPointA

<instance> getPointA([vec2])

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
vec2Phaser.Math.Vector2YesA Vector2 object to set the results in. If undefined a new Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object that corresponds to the start of this Line.

Source: src/geom/line/Line.js#L197
Since: 3.0.0


getPointB

<instance> getPointB([vec2])

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
vec2Phaser.Math.Vector2YesA Vector2 object to set the results in. If undefined a new Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object that corresponds to the end of this Line.

Source: src/geom/line/Line.js#L218
Since: 3.0.0


getPoints

<instance> getPoints(quantity, [stepRate], [output])

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
quantitynumberNoThe number of points to place on the line. Set to 0 to use stepRate instead.
stepRatenumberYesThe distance between each point on the line. When set, quantity is implied and should be set to 0.
outputArray.<Phaser.Math.Vector2>YesAn optional array of Vector2 objects to store the coordinates of the points on the line.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 objects containing the coordinates of the points on the line.

Source: src/geom/line/Line.js#L105
Since: 3.0.0


GetPoints

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

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.

See also GetEasedPoints for a way to distribute the points across the line according to an ease type or input function.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line.
quantitynumberNoThe number of points to place on the line. Set to 0 to use stepRate instead.
stepRatenumberYesThe distance between each point on the line. When set, quantity is implied and should be set to 0.
outArray.<Phaser.Math.Vector2>YesAn optional array of Vector2 objects to store the coordinates of the points on the line.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 objects containing the coordinates of the points on the line.

Source: src/geom/line/GetPoints.js#L10
Since: 3.0.0


getRandomPoint

<instance> getRandomPoint([point])

Description:

Get a random Point on the Line.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
pointPhaser.Math.Vector2YesAn instance of a Vector2 to be modified.

Returns: Phaser.Math.Vector2 - A random point on the Line.

Source: src/geom/line/Line.js#L129
Since: 3.0.0


GetShortestDistance

<static> GetShortestDistance(line, point)

Description:

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

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to get the distance from.
pointPhaser.Types.Math.Vector2LikeNoThe point to get the shortest distance to.

Returns: boolean, number - The shortest distance from the line to the point, or false.

Source: src/geom/line/GetShortestDistance.js#L8
Since: 3.16.0


Height

<static> Height(line)

Description:

Calculate the height of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the height of.

Returns: number - The height of the line.

Source: src/geom/line/Height.js#L7
Since: 3.0.0


Length

<static> Length(line)

Description:

Calculate the length of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the length of.

Returns: number - The length of the line.

Source: src/geom/line/Length.js#L7
Since: 3.0.0


NormalAngle

<static> NormalAngle(line)

Description:

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

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the angle of the normal of.

Returns: number - The angle of the normal of the line in radians.

Source: src/geom/line/NormalAngle.js#L11
Since: 3.0.0


NormalX

<static> NormalX(line)

Description:

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

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe Line object to get the normal value from.

Returns: number - The x component of the normal vector of the line.

Source: src/geom/line/NormalX.js#L10
Since: 3.0.0


NormalY

<static> NormalY(line)

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:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the normal of.

Returns: number - The Y value of the normal of the Line.

Source: src/geom/line/NormalY.js#L10
Since: 3.0.0


Offset

<static> Offset(line, x, y)

Description:

Offset a line by the given amount.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to offset.
xnumberNoThe horizontal offset to add to the line.
ynumberNoThe vertical offset to add to the line.

Returns: Phaser.Geom.Line - The offset line.

Source: src/geom/line/Offset.js#L7
Since: 3.0.0


PerpSlope

<static> PerpSlope(line)

Description:

Calculate the perpendicular slope of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the perpendicular slope of.

Returns: number - The perpendicular slope of the line.

Source: src/geom/line/PerpSlope.js#L7
Since: 3.0.0


Random

<static> Random(line, [out])

Description:

Returns a random point on a given Line.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe Line to calculate the random point on.
outPhaser.Math.Vector2YesAn instance of a Vector2 to be modified.

Returns: Phaser.Math.Vector2 - A random point on the Line stored in a Vector2.

Source: src/geom/line/Random.js#L9
Since: 3.0.0


ReflectAngle

<static> ReflectAngle(lineA, lineB)

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:

nametypeoptionaldescription
lineAPhaser.Geom.LineNoThe first line.
lineBPhaser.Geom.LineNoThe second line.

Returns: number - The reflected angle between each line.

Source: src/geom/line/ReflectAngle.js#L10
Since: 3.0.0


Rotate

<static> Rotate(line, angle)

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to rotate.
anglenumberNoThe angle of rotation in radians.

Returns: Phaser.Geom.Line - The rotated line.

Source: src/geom/line/Rotate.js#L9
Since: 3.0.0


RotateAroundPoint

<static> RotateAroundPoint(line, point, angle)

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to rotate.
pointPhaser.Math.Vector2NoThe point to rotate the line around.
anglenumberNoThe angle of rotation in radians.

Returns: Phaser.Geom.Line - The rotated line.

Source: src/geom/line/RotateAroundPoint.js#L9
Since: 3.0.0


RotateAroundXY

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

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to rotate.
xnumberNoThe horizontal coordinate to rotate the line around.
ynumberNoThe vertical coordinate to rotate the line around.
anglenumberNoThe angle of rotation in radians.

Returns: Phaser.Geom.Line - The rotated line.

Source: src/geom/line/RotateAroundXY.js#L7
Since: 3.0.0


setFromObjects

<instance> setFromObjects(start, end)

Description:

Sets this Line to match the x/y coordinates of the two given Vector2Like objects.

Parameters:

nametypeoptionaldescription
startPhaser.Types.Math.Vector2LikeNoAny object with public x and y properties, whose values will be assigned to the x1/y1 components of this Line.
endPhaser.Types.Math.Vector2LikeNoAny object with public x and y properties, whose values will be assigned to the x2/y2 components of this Line.

Returns: Phaser.Geom.Line - This Line object.

Source: src/geom/line/Line.js#L175
Since: 3.70.0


setTo

<instance> setTo([x1], [y1], [x2], [y2])

Description:

Set new coordinates for the line endpoints.

Parameters:

nametypeoptionaldefaultdescription
x1numberYes0The x coordinate of the lines starting point.
y1numberYes0The y coordinate of the lines starting point.
x2numberYes0The x coordinate of the lines ending point.
y2numberYes0The y coordinate of the lines ending point.

Returns: Phaser.Geom.Line - This Line object.

Source: src/geom/line/Line.js#L146
Since: 3.0.0


SetToAngle

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

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to set.
xnumberNoThe horizontal start position of the line.
ynumberNoThe vertical start position of the line.
anglenumberNoThe angle of the line in radians.
lengthnumberNoThe length of the line.

Returns: Phaser.Geom.Line - The updated line.

Source: src/geom/line/SetToAngle.js#L7
Since: 3.0.0


Slope

<static> Slope(line)

Description:

Calculate the slope of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the slope of.

Returns: number - The slope of the line.

Source: src/geom/line/Slope.js#L7
Since: 3.0.0


Width

<static> Width(line)

Description:

Calculate the width of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the width of.

Returns: number - The width of the line.

Source: src/geom/line/Width.js#L7
Since: 3.0.0


Public Members

bottom

bottom: number

Description:

The bottom position of the Line.

Source: src/geom/line/Line.js#L323
Since: 3.0.0


left

left: number

Description:

The left position of the Line.

Source: src/geom/line/Line.js#L239
Since: 3.0.0


right: number

Description:

The right position of the Line.

Source: src/geom/line/Line.js#L267
Since: 3.0.0


top

top: number

Description:

The top position of the Line.

Source: src/geom/line/Line.js#L295
Since: 3.0.0


type

type: number

Description:

The geometry constant type of this object: GEOM_CONST.LINE.

Used for fast type comparisons.

Source: src/geom/line/Line.js#L39
Since: 3.19.0


x1

x1: number

Description:

The x coordinate of the lines starting point.

Source: src/geom/line/Line.js#L50
Since: 3.0.0


x2

x2: number

Description:

The x coordinate of the lines ending point.

Source: src/geom/line/Line.js#L68
Since: 3.0.0


y1

y1: number

Description:

The y coordinate of the lines starting point.

Source: src/geom/line/Line.js#L59
Since: 3.0.0


y2

y2: number

Description:

The y coordinate of the lines ending point.

Source: src/geom/line/Line.js#L77
Since: 3.0.0