new Line([x1], [y1], [x2], [y2])
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. |
The bottom position of the Line.
The left position of the Line.
The right position of the Line.
The top position of the Line.
The geometry constant type of this object: GEOM_CONST.LINE
.
Used for fast type comparisons.
The x coordinate of the lines starting point.
The x coordinate of the lines ending point.
The y coordinate of the lines starting point.
The y coordinate of the lines ending point.
Get a point on a line that's a given percentage along its length.
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. |
A Point, or point-like object, containing the coordinates of the point on the line.
Returns a Vector2 object that corresponds to the start of this Line.
name | type | arguments | description |
---|---|---|---|
vec2 | Phaser.Math.Vector2 | <optional> |
A Vector2 object to set the results in. If |
A Vector2 object that corresponds to the start of this Line.
Returns a Vector2 object that corresponds to the end of this Line.
name | type | arguments | description |
---|---|---|---|
vec2 | Phaser.Math.Vector2 | <optional> |
A Vector2 object to set the results in. If |
A Vector2 object that corresponds to the end of this 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
.
name | type | arguments | description |
---|---|---|---|
quantity | number |
The number of points to place on the line. Set to |
|
stepRate | number | <optional> |
The distance between each point on the line. When set, |
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. |
An array of Points, or point-like objects, containing the coordinates of the points on the line.
Get a random Point on the Line.
name | type | arguments | description |
---|---|---|---|
point | object | Phaser.Geom.Point | <optional> |
An instance of a Point to be modified. |
A random Point on the Line.
Set new coordinates for the line endpoints.
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. |
This Line object.
Calculate the angle of the line in radians.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the angle of. |
The angle of the line, in radians.
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.
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. |
The array of coordinates on the line.
Center a line on the given coordinates.
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. |
The centered line.
Clone the given line.
name | type | description |
---|---|---|
source | Phaser.Geom.Line |
The source line to clone. |
The cloned line.
Copy the values of one line to a destination line.
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. |
The destination line.
Compare two lines for strict equality.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The first line to compare. |
toCompare | Phaser.Geom.Line |
The second line to compare. |
Whether the two lines are equal.
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.
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 |
The modified Line instance.
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.
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 | 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. |
An array of Geom.Points containing the coordinates of the points on the line.
Get the midpoint of the given line.
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. |
The midpoint of the Line.
Get the nearest point on a line perpendicular to the given point.
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. |
The nearest point on the line.
Calculate the normal of the given line.
The normal of a line is a vector that points perpendicular from it.
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. |
The normal of the Line.
Get a point on a line that's a given percentage along its length.
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. |
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
.
name | type | arguments | description |
---|---|---|---|
line | Phaser.Geom.Line |
The line. |
|
quantity | number |
The number of points to place on the line. Set to |
|
stepRate | number | <optional> |
The distance between each point on the line. When set, |
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. |
An array of Points, or point-like objects, containing the coordinates of the points on the line.
Get the shortest distance from a Line to the given Point.
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. |
The shortest distance from the line to the point.
Calculate the height of the given line.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the height of. |
The height of the line.
Calculate the length of the given line.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the length of. |
The length of the line.
Get the angle of the normal of the given line in radians.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the angle of the normal of. |
The angle of the normal of the line in radians.
Returns the x component of the normal vector of the given line.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The Line object to get the normal value from. |
The x component of the normal vector of the line.
The Y value of the normal of the given line. The normal of a line is a vector that points perpendicular from it.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the normal of. |
The Y value of the normal of the Line.
Offset a line by the given amount.
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. |
The offset line.
Calculate the perpendicular slope of the given line.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the perpendicular slope of. |
The perpendicular slope of the line.
Returns a random point on a given Line.
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. |
A random Point on the Line.
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.
name | type | description |
---|---|---|
lineA | Phaser.Geom.Line |
The first line. |
lineB | Phaser.Geom.Line |
The second line. |
The reflected angle between each line.
Rotate a line around its midpoint by the given angle in radians.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to rotate. |
angle | number |
The angle of rotation in radians. |
The rotated line.
Rotate a line around a point by the given angle in radians.
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. |
The rotated line.
Rotate a line around the given coordinates by the given angle in radians.
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. |
The rotated line.
Set a line to a given position, angle and length.
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. |
The updated line.
Calculate the slope of the given line.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the slope of. |
The slope of the line.
Calculate the width of the given line.
name | type | description |
---|---|---|
line | Phaser.Geom.Line |
The line to calculate the width of. |
The width of the line.