Optionalx1: number
The x coordinate of the line's starting point. Default 0.
Optionaly1: number
The y coordinate of the line's starting point. Default 0.
Optionalx2: number
The x coordinate of the line's ending point. Default 0.
Optionaly2: number
The y coordinate of the line's ending point. Default 0.
The bottom-most y coordinate of this Line, i.e. the greater of y1 and y2.
When set, the endpoint that currently holds the larger y value is moved to the new position.
The left-most x coordinate of this Line, i.e. the lesser of x1 and x2.
When set, the endpoint that currently holds the smaller x value is moved to the new position.
The right-most x coordinate of this Line, i.e. the greater of x1 and x2.
When set, the endpoint that currently holds the larger x value is moved to the new position.
The top-most y coordinate of this Line, i.e. the lesser of y1 and y2.
When set, the endpoint that currently holds the smaller y value is moved to the new position.
ReadonlytypeThe geometry constant type of this object: GEOM_CONST.LINE.
Used for fast type comparisons.
The x coordinate of the line's starting point.
The x coordinate of the line's ending point.
The y coordinate of the line's starting point.
The y coordinate of the line's ending point.
Get a point on a line that's a given percentage along its length.
A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.
Optionaloutput: O
An optional Vector2 object to store the coordinates of the point on the line.
A Vector2 object containing the coordinates of the point on the line.
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.
The number of points to place on the line. Set to 0 to use stepRate instead.
OptionalstepRate: number
The distance between each point on the line. When set, quantity is implied and should be set to 0.
Optionaloutput: O
An optional array of Vector2 objects to store the coordinates of the points on the line.
An array of Vector2 objects containing the coordinates of the points on the line.
Returns a randomly chosen point on this Line, selected with uniform distribution along its length. If a Vector2 is provided it will be populated with the result and returned; otherwise a new Vector2 is created.
Optionalpoint: O
An instance of a Vector2 to be modified.
A random point on the Line.
Sets this Line to match the x/y coordinates of the two given Vector2Like objects.
Any object with public x and y properties, whose values will be assigned to the x1/y1 components of this Line.
Any object with public x and y properties, whose values will be assigned to the x2/y2 components of this Line.
This Line object.
Set new coordinates for the line endpoints.
Optionalx1: number
The x coordinate of the line's starting point. Default 0.
Optionaly1: number
The y coordinate of the line's starting point. Default 0.
Optionalx2: number
The x coordinate of the line's ending point. Default 0.
Optionaly2: number
The y coordinate of the line's ending point. Default 0.
This Line object.
StaticAngleCalculate the angle of the line in radians.
The line to calculate the angle of.
The angle of the line, in radians.
StaticBresenhamUsing Bresenham's line algorithm this will return an array of all coordinates on the given line.
The start and end points are rounded before this runs as the algorithm works on integers.
The line.
OptionalstepRate: number
Controls how densely the points are sampled along the line. A value of 1 returns every integer coordinate; a value of 2 returns every other coordinate, and so on. Default 1.
Optionalresults: Vector2Like[]
An optional array to push the resulting coordinates into.
The array of coordinates on the line.
StaticCenterStaticCloneStaticCopyStaticEqualsCompares two lines for strict equality. Two lines are considered equal if their start
and end point coordinates all match exactly: x1, y1, x2, and y2.
true if the two lines have identical start and end point coordinates, otherwise false.
StaticExtendExtends the start and end points of a Line by the given amounts.
The amounts can be positive or negative. Positive values 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.
The left value extends outward from the start point (x1, y1) along the line's direction, and the right value extends outward from the end point (x2, y2).
The line instance to extend.
The amount to extend the start of the line by.
Optionalright: number
The amount to extend the end of the line by. If not given it will be set to the left value.
The modified Line instance.
StaticGetReturns 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.
The Line object.
The ease to use. This can be either a string from the EaseMap, or a custom function.
The number of points to return. Note that if you provide a collinearThreshold, the resulting array may not always contain this number of points.
OptionalcollinearThreshold: number
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 noisy eases. Default 0.
OptionaleaseParams: number[]
An optional array of ease parameters to go with the ease.
An array of Math.Vector2s containing the coordinates of the points on the line.
StaticGetStaticGetStaticGetStaticGetStaticGetGet a number of evenly-spaced points along a line, starting from the first endpoint (x1, y1). The last endpoint (x2, y2) is not included in the returned points.
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.
The line.
The number of points to place on the line. Set to 0 to use stepRate instead.
OptionalstepRate: number
The distance between each point on the line. When set, quantity is calculated as the line length divided by this value; quantity should be set to 0.
Optionalout: O
An optional array of Vector2 objects to store the coordinates of the points on the line.
An array of Vector2 objects containing the coordinates of the points on the line.
StaticGetCalculates the shortest (perpendicular) distance from an infinite line, defined by the two
endpoints of the given Line object, to the given Point. If the line has zero length (both
endpoints are identical), this function returns false.
The line to get the distance from.
The point to get the shortest distance to.
The shortest perpendicular distance from the line to the point, or false if the line has zero length.
StaticHeightCalculate the height of the given line.
The line to calculate the height of.
The height of the line.
StaticLengthCalculate the length of the given line.
The line to calculate the length of.
The length of the line.
StaticNormalGet the angle of the normal of the given line in radians.
The line to calculate the angle of the normal of.
The angle of the normal of the line in radians.
StaticNormalReturns the x component of the normal vector of the given line.
The Line object to get the normal value from.
The x component of the normal vector of the line.
StaticNormalThe Y value of the normal of the given line. The normal of a line is a vector that points perpendicular from it.
The line to calculate the normal of.
The Y value of the normal of the Line.
StaticOffsetTranslates both endpoints of the given Line by the specified horizontal and vertical amounts, effectively moving the line to a new position in 2D space while preserving its length and angle.
The line to offset.
The horizontal offset to add to the line.
The vertical offset to add to the line.
The modified Line object, with both endpoints moved by the given offset.
StaticPerpCalculate the perpendicular slope of the given line.
The line to calculate the perpendicular slope of.
The perpendicular slope of the line.
StaticRandomStaticReflectCalculates the reflected angle of Line A off the surface represented by Line B. This is the outgoing angle based on the angle of incidence (Line A) and the surface normal of Line B. The result is in radians.
The reflected angle of Line A off the surface of Line B, in radians.
StaticRotateStaticRotateStaticRotateRotate a line around the given coordinates by the given angle in radians.
The line to rotate.
The horizontal coordinate to rotate the line around.
The vertical coordinate to rotate the line around.
The angle of rotation in radians.
The rotated line.
StaticSetSet a line to a given position, angle and length.
The line to set.
The horizontal start position of the line.
The vertical start position of the line.
The angle of the line in radians.
The length of the line.
The updated line.
StaticSlopeCalculate the slope of the given line.
The line to calculate the slope of.
The slope of the line.
StaticWidthCalculates the width of the given line, defined as the absolute difference between
the x-coordinates of its two endpoints (x1 and x2). This represents the
horizontal extent of the line, not its geometric length. To get the true length
of the line, use Phaser.Geom.Line.Length instead.
The line to calculate the width of.
The width of the line, i.e. the absolute difference between its x1 and x2 coordinates.
Defines a Line segment: a finite portion of a line described by a start point (
x1,y1) and an end point (x2,y2). Unlike an infinite mathematical line, a Line segment has a fixed length and direction.Line segments are used throughout Phaser for collision detection, geometry calculations, path and boundary definitions, and placement utilities. You can retrieve a point at any percentage along the line via
getPoint, get an array of evenly-spaced points viagetPoints, or query the bounding extents through theleft,right,top, andbottomaccessors.