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 code: geom/Line.js, line 17
Public Properties

[readonly] angle : number

Gets the angle of the line.
 Source code: geom/Line.js, line 257

[readonly] bottom : number

Gets the bottommost point of this line.
 Source code: geom/Line.js, line 361

end : Phaser.Point

The end point of the line.
 Source code: geom/Line.js, line 32

[readonly] height : number

Gets the height of this bounds of this line.
 Source code: geom/Line.js, line 387

[readonly] left : number

Gets the leftmost point of this line.
 Source code: geom/Line.js, line 322

[readonly] length : number

Gets the length of the line segment.
 Source code: geom/Line.js, line 244

[readonly] normalAngle : number

Gets the angle in radians of the normal of this line (line.angle  90 degrees.)
 Source code: geom/Line.js, line 426

[readonly] normalX : number

Gets the x component of the lefthand normal of this line.
 Source code: geom/Line.js, line 400

[readonly] normalY : number

Gets the y component of the lefthand normal of this line.
 Source code: geom/Line.js, line 413

[readonly] perpSlope : number

Gets the perpendicular slope of the line (x/y).
 Source code: geom/Line.js, line 283

[readonly] right : number

Gets the rightmost point of this line.
 Source code: geom/Line.js, line 335

[readonly] slope : number

Gets the slope of the line (y/x).
 Source code: geom/Line.js, line 270

start : Phaser.Point

The start point of the line.
 Source code: geom/Line.js, line 27

[readonly] top : number

Gets the topmost point of this line.
 Source code: geom/Line.js, line 348

[readonly] width : number

Gets the width of this bounds of this line.
 Source code: geom/Line.js, line 374

[readonly] x : number

Gets the x coordinate of the top left of the bounds around this line.
 Source code: geom/Line.js, line 296

[readonly] y : number

Gets the y coordinate of the top left of the bounds around this line.
 Source code: geom/Line.js, line 309
Public Methods

<static> intersects(a, b, asSegment, result) → {Phaser.Point}

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.
Returns
The intersection segment of the two lines as a Point, or null if there is no intersection.
 Source code: geom/Line.js, line 495

<static> intersectsPoints(a, b, e, f, asSegment, result) → {Phaser.Point}

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.
Returns
The intersection segment of the two lines as a Point, or null if there is no intersection.
 Source code: geom/Line.js, line 439

<static> reflect(a, b) → {number}

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.
Returns
number The reflected angle in radians.
 Source code: geom/Line.js, line 515

clone(output) → {Phaser.Line}

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.
Returns
The cloned Line object.
 Source code: geom/Line.js, line 221

coordinatesOnLine(stepRate, results) → {array}

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.
Returns
array An array of coordinates.
 Source code: geom/Line.js, line 163

fromAngle(x, y, angle, length) → {Phaser.Line}

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.
Returns
This line object
 Source code: geom/Line.js, line 80

fromSprite(startSprite, endSprite, useCenter) → {Phaser.Line}

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.center.x, if false startSprite.x. Note that Sprites don't have a center property by default, so only enable if you've overridden your Sprite with a custom class.
Returns
This line object
 Source code: geom/Line.js, line 57

intersects(line, asSegment, result) → {Phaser.Point}

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.
Returns
The intersection segment of the two lines as a Point, or null if there is no intersection.
 Source code: geom/Line.js, line 99

pointOnLine(x, y) → {boolean}

Tests if the given coordinates fall on this line. See pointOnSegment to test against just the line segment.
Parameters
Name Type Description x
number The line to check against this one.
y
number The line to check against this one.
Returns
boolean True if the point is on the line, false if not.
 Source code: geom/Line.js, line 130

pointOnSegment(x, y) → {boolean}

Tests if the given coordinates fall on this line and within the segment. See pointOnLine to test against just the line.
Parameters
Name Type Description x
number The line to check against this one.
y
number The line to check against this one.
Returns
boolean True if the point is on the line and segment, false if not.
 Source code: geom/Line.js, line 144

reflect(line) → {number}

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.
Returns
number The reflected angle in radians.
 Source code: geom/Line.js, line 116

setTo(x1, y1, x2, y2) → {Phaser.Line}

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.
Returns
This line object
 Source code: geom/Line.js, line 38