new Line( [x1] [, y1] [, x2] [, y2])
Creates a new Line object with a start and an end point.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
x1 |
number |
<optional> |
0 | The x coordinate of the start of the line. |
y1 |
number |
<optional> |
0 | The y coordinate of the start of the line. |
x2 |
number |
<optional> |
0 | The x coordinate of the end of the line. |
y2 |
number |
<optional> |
0 | The y coordinate of the end of the line. |
- Source:
- src/geom/Line.js line 17
Members
-
<readonly> angle : number
-
Gets the angle of the line in radians.
Type:
- number
- Source:
- src/geom/Line.js line 374
-
<readonly> bottom : number
-
Gets the bottom-most point of this line.
Type:
- number
- Source:
- src/geom/Line.js line 478
-
end : Phaser.Point
-
The end point of the line.
Type:
- Source:
- src/geom/Line.js line 32
-
<readonly> height : number
-
Gets the height of this bounds of this line.
Type:
- number
- Source:
- src/geom/Line.js line 504
-
<readonly> left : number
-
Gets the left-most point of this line.
Type:
- number
- Source:
- src/geom/Line.js line 439
-
<readonly> length : number
-
Gets the length of the line segment.
Type:
- number
- Source:
- src/geom/Line.js line 361
-
<readonly> normalAngle : number
-
Gets the angle in radians of the normal of this line (line.angle - 90 degrees.)
Type:
- number
- Source:
- src/geom/Line.js line 543
-
<readonly> normalX : number
-
Gets the x component of the left-hand normal of this line.
Type:
- number
- Source:
- src/geom/Line.js line 517
-
<readonly> normalY : number
-
Gets the y component of the left-hand normal of this line.
Type:
- number
- Source:
- src/geom/Line.js line 530
-
<readonly> perpSlope : number
-
Gets the perpendicular slope of the line (x/y).
Type:
- number
- Source:
- src/geom/Line.js line 400
-
<readonly> right : number
-
Gets the right-most point of this line.
Type:
- number
- Source:
- src/geom/Line.js line 452
-
<readonly> slope : number
-
Gets the slope of the line (y/x).
Type:
- number
- Source:
- src/geom/Line.js line 387
-
start : Phaser.Point
-
The start point of the line.
Type:
- Source:
- src/geom/Line.js line 27
-
<readonly> top : number
-
Gets the top-most point of this line.
Type:
- number
- Source:
- src/geom/Line.js line 465
-
<readonly> type : number
-
The const type of this object.
Type:
- number
- Source:
- src/geom/Line.js line 38
-
<readonly> width : number
-
Gets the width of this bounds of this line.
Type:
- number
- Source:
- src/geom/Line.js line 491
-
<readonly> x : number
-
Gets the x coordinate of the top left of the bounds around this line.
Type:
- number
- Source:
- src/geom/Line.js line 413
-
<readonly> y : number
-
Gets the y coordinate of the top left of the bounds around this line.
Type:
- number
- Source:
- src/geom/Line.js line 426
Methods
-
<static> intersects(a, b [, asSegment] [, result])
-
Checks for intersection between two lines. If asSegment is true it will check for segment intersection. If asSegment is false it will check for line intersection. Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. Adapted from code by Keith Hair
Parameters:
Name Type Argument Default Description a
Phaser.Line The first Line to be checked.
b
Phaser.Line The second Line to be checked.
asSegment
boolean <optional>
true If true it will check for segment intersection, otherwise full line intersection.
result
Phaser.Point <optional>
A Point object to store the result in, if not given a new one will be created.
- Source:
- src/geom/Line.js line 612
Returns:
The intersection segment of the two lines as a Point, or null if there is no intersection.
- Type
- Phaser.Point
-
<static> intersectsPoints(a, b, e, f [, asSegment] [, result])
-
Checks for intersection between two lines as defined by the given start and end points. If asSegment is true it will check for line segment intersection. If asSegment is false it will check for line intersection. Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. Adapted from code by Keith Hair
Parameters:
Name Type Argument Default Description a
Phaser.Point The start of the first Line to be checked.
b
Phaser.Point The end of the first line to be checked.
e
Phaser.Point The start of the second Line to be checked.
f
Phaser.Point The end of the second line to be checked.
asSegment
boolean <optional>
true If true it will check for segment intersection, otherwise full line intersection.
result
Phaser.Point | object <optional>
A Point object to store the result in, if not given a new one will be created.
- Source:
- src/geom/Line.js line 556
Returns:
The intersection segment of the two lines as a Point, or null if there is no intersection.
- Type
- Phaser.Point
-
<static> intersectsRectangle(line, rect)
-
Checks for intersection between the Line and a Rectangle shape, or a rectangle-like object, with public
x
,y
,right
andbottom
properties, such as a Sprite or Body.An intersection is considered valid if:
The line starts within or ends within the rectangle; or The line segment intersects one of the 4 rectangle edges; and The line has a non-zero length; and The rectangle is not empty.
For the purposes of this function rectangles are considered 'solid'.
Parameters:
Name Type Description line
Phaser.Line The line to check for intersection with.
rect
Phaser.Rectangle | object The rectangle, or rectangle-like object, to check for intersection with.
- Source:
- src/geom/Line.js line 632
Returns:
True if the line intersects with the rectangle edges, or starts or ends within the rectangle.
- Type
- boolean
-
<static> reflect(a, b)
-
Returns 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 a
Phaser.Line The base line.
b
Phaser.Line The line to be reflected from the base line.
- Source:
- src/geom/Line.js line 726
Returns:
The reflected angle in radians.
- Type
- number
-
centerOn(x, y)
-
Centers this Line on the given coordinates.
The line is centered by positioning the start and end points so that the lines midpoint matches the coordinates given.
Parameters:
Name Type Description x
number The x position to center the line on.
y
number The y position to center the line on.
- Source:
- src/geom/Line.js line 200
Returns:
This line object
- Type
- Phaser.Line
-
clone(output)
-
Returns a new Line object with the same values for the start and end properties as this Line object.
Parameters:
Name Type Description output
Phaser.Line Optional Line object. If given the values will be set into the object, otherwise a brand new Line object will be created and returned.
- Source:
- src/geom/Line.js line 338
Returns:
The cloned Line object.
- Type
- Phaser.Line
-
coordinatesOnLine( [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 stepRate
number <optional>
1 How many steps will we return? 1 = every coordinate on the line, 2 = every other coordinate, etc.
results
array <optional>
The array to store the results in. If not provided a new one will be generated.
- Source:
- src/geom/Line.js line 280
Returns:
An array of coordinates.
- Type
- array
-
fromAngle(x, y, angle, length)
-
Sets this line to start at the given
x
andy
coordinates and for the segment to extend atangle
for the givenlength
.Parameters:
Name Type Description x
number The x coordinate of the start of the line.
y
number The y coordinate of the start of the line.
angle
number The angle of the line in radians.
length
number The length of the line in pixels.
- Source:
- src/geom/Line.js line 86
Returns:
This line object
- Type
- Phaser.Line
-
fromSprite(startSprite, endSprite [, useCenter])
-
Sets the line to match the x/y coordinates of the two given sprites. Can optionally be calculated from their center coordinates.
Parameters:
Name Type Argument Default Description startSprite
Phaser.Sprite The coordinates of this Sprite will be set to the Line.start point.
endSprite
Phaser.Sprite The coordinates of this Sprite will be set to the Line.start point.
useCenter
boolean <optional>
false If true it will use startSprite.centerX, if false startSprite.x.
- Source:
- src/geom/Line.js line 63
Returns:
This line object
- Type
- Phaser.Line
-
intersects(line [, asSegment] [, result])
-
Checks for intersection between this line and another Line. If asSegment is true it will check for segment intersection. If asSegment is false it will check for line intersection. Returns the intersection segment of AB and EF as a Point, or null if there is no intersection.
Parameters:
Name Type Argument Default Description line
Phaser.Line The line to check against this one.
asSegment
boolean <optional>
true If true it will check for segment intersection, otherwise full line intersection.
result
Phaser.Point <optional>
A Point object to store the result in, if not given a new one will be created.
- Source:
- src/geom/Line.js line 151
Returns:
The intersection segment of the two lines as a Point, or null if there is no intersection.
- Type
- Phaser.Point
-
midPoint( [out])
-
Returns a Point object where the x and y values correspond to the center (or midpoint) of the Line segment.
Parameters:
Name Type Argument Description out
Phaser.Point <optional>
A Phaser.Point object into which the result will be populated. If not given a new Point object is created.
- Source:
- src/geom/Line.js line 182
Returns:
A Phaser.Point object with the x and y values set to the center of the line segment.
- Type
- Phaser.Point
-
pointOnLine(x, y [, epsilon])
-
Tests if the given coordinates fall on this line. See pointOnSegment to test against just the line segment.
Parameters:
Name Type Argument Default Description x
number The line to check against this one.
y
number The line to check against this one.
epsilon
number <optional>
0 Range for a fuzzy comparison, e.g., 0.0001.
- Source:
- src/geom/Line.js line 224
Returns:
True if the point is on the line, false if not.
- Type
- boolean
-
pointOnSegment(x, y [, epsilon])
-
Tests if the given coordinates fall on this line and within the segment. See pointOnLine to test against just the line.
Parameters:
Name Type Argument Default Description x
number The line to check against this one.
y
number The line to check against this one.
epsilon
number <optional>
0 Range for a fuzzy comparison, e.g., 0.0001.
- Source:
- src/geom/Line.js line 239
Returns:
True if the point is on the line and segment, false if not.
- Type
- boolean
-
random( [out])
-
Picks a random point from anywhere on the Line segment and returns it.
Parameters:
Name Type Argument Description out
Phaser.Point | object <optional>
A Phaser.Point, or any object with public x/y properties, that the values will be set in. If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an object.
- Source:
- src/geom/Line.js line 259
Returns:
An object containing the random point in its
x
andy
properties.- Type
- Phaser.Point
-
reflect(line)
-
Returns the reflected angle between two lines. This is the outgoing angle based on the angle of this line and the normalAngle of the given line.
Parameters:
Name Type Description line
Phaser.Line The line to reflect off this line.
- Source:
- src/geom/Line.js line 168
Returns:
The reflected angle in radians.
- Type
- number
-
rotate(angle [, asDegrees])
-
Rotates the line by the amount specified in
angle
.Rotation takes place from the center of the line. If you wish to rotate around a different point see Line.rotateAround.
If you wish to rotate the ends of the Line then see Line.start.rotate or Line.end.rotate.
Parameters:
Name Type Argument Default Description angle
number The angle in radians (unless asDegrees is true) to rotate the line by.
asDegrees
boolean <optional>
false Is the given angle in radians (false) or degrees (true)?
- Source:
- src/geom/Line.js line 105
Returns:
This line object
- Type
- Phaser.Line
-
rotateAround(x, y, angle [, asDegrees])
-
Rotates the line by the amount specified in
angle
.Rotation takes place around the coordinates given.
Parameters:
Name Type Argument Default Description x
number The x coordinate to offset the rotation from.
y
number The y coordinate to offset the rotation from.
angle
number The angle in radians (unless asDegrees is true) to rotate the line by.
asDegrees
boolean <optional>
false Is the given angle in radians (false) or degrees (true)?
- Source:
- src/geom/Line.js line 130
Returns:
This line object
- Type
- Phaser.Line
-
setTo( [x1] [, y1] [, x2] [, y2])
-
Sets the components of the Line to the specified values.
Parameters:
Name Type Argument Default Description x1
number <optional>
0 The x coordinate of the start of the line.
y1
number <optional>
0 The y coordinate of the start of the line.
x2
number <optional>
0 The x coordinate of the end of the line.
y2
number <optional>
0 The y coordinate of the end of the line.
- Source:
- src/geom/Line.js line 44
Returns:
This line object
- Type
- Phaser.Line