new Line(x1, y1, x2, y2) → {Phaser.Line}
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:
Returns:
This line object
- Type
- Phaser.Line
Members
-
<readonly> angle
-
- Source:
Properties:
Name Type Description anglenumber Gets the angle of the line.
-
<readonly> bottom
-
- Source:
Properties:
Name Type Description bottomnumber Gets the bottom-most point of this line.
-
end
-
- Source:
Properties:
Name Type Description endPhaser.Point The end point of the line.
-
<readonly> height
-
- Source:
Properties:
Name Type Description heightnumber Gets the height of this bounds of this line.
-
<readonly> left
-
- Source:
Properties:
Name Type Description leftnumber Gets the left-most point of this line.
-
<readonly> length
-
- Source:
Properties:
Name Type Description lengthnumber Gets the length of the line segment.
-
<readonly> perpSlope
-
- Source:
Properties:
Name Type Description perpSlopenumber Gets the perpendicular slope of the line (x/y).
-
<readonly> right
-
- Source:
Properties:
Name Type Description rightnumber Gets the right-most point of this line.
-
<readonly> slope
-
- Source:
Properties:
Name Type Description slopenumber Gets the slope of the line (y/x).
-
start
-
- Source:
Properties:
Name Type Description startPhaser.Point The start point of the line.
-
<readonly> top
-
- Source:
Properties:
Name Type Description topnumber Gets the top-most point of this line.
-
<readonly> width
-
- Source:
Properties:
Name Type Description widthnumber Gets the width of this bounds of this line.
-
<readonly> x
-
- Source:
Properties:
Name Type Description xnumber Gets the x coordinate of the top left of the bounds around this line.
-
<readonly> y
-
- Source:
Properties:
Name Type Description ynumber Gets the y coordinate of the top left of the bounds around this line.
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 aPhaser.Line The first Line to be checked.
bPhaser.Line The second Line to be checked.
asSegmentboolean <optional>
true If true it will check for segment intersection, otherwise full line intersection.
resultPhaser.Point <optional>
A Point object to store the result in, if not given a new one will be created.
- Source:
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) → {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 aPhaser.Point The start of the first Line to be checked.
bPhaser.Point The end of the first line to be checked.
ePhaser.Point The start of the second Line to be checked.
fPhaser.Point The end of the second line to be checked.
asSegmentboolean <optional>
true If true it will check for segment intersection, otherwise full line intersection.
resultPhaser.Point <optional>
A Point object to store the result in, if not given a new one will be created.
- Source:
Returns:
The intersection segment of the two lines as a Point, or null if there is no intersection.
- Type
- Phaser.Point
-
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 outputPhaser.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:
Returns:
The cloned Line object.
- Type
- Phaser.Line
-
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 stepRatenumber <optional>
1 How many steps will we return? 1 = every coordinate on the line, 2 = every other coordinate, etc.
resultsarray <optional>
The array to store the results in. If not provided a new one will be generated.
- Source:
Returns:
An array of coordinates.
- Type
- array
-
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 startSpritePhaser.Sprite The coordinates of this Sprite will be set to the Line.start point.
endSpritePhaser.Sprite The coordinates of this Sprite will be set to the Line.start point.
useCenterboolean <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 over-ridden your Sprite with a custom class.
- Source:
Returns:
This line object
- Type
- Phaser.Line
-
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 linePhaser.Line The line to check against this one.
asSegmentboolean <optional>
true If true it will check for segment intersection, otherwise full line intersection.
resultPhaser.Point <optional>
A Point object to store the result in, if not given a new one will be created.
- Source:
Returns:
The intersection segment of the two lines as a Point, or null if there is no intersection.
- Type
- Phaser.Point
-
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 xnumber The line to check against this one.
ynumber The line to check against this one.
- Source:
Returns:
True if the point is on the line, false if not.
- Type
- boolean
-
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 xnumber The line to check against this one.
ynumber The line to check against this one.
- Source:
Returns:
True if the point is on the line and segment, false if not.
- Type
- boolean
-
setTo(x1, y1, x2, y2) → {Phaser.Line}
-
Sets the components of the Line to the specified values.
Parameters:
Name Type Argument Default Description x1number <optional>
0 The x coordinate of the start of the line.
y1number <optional>
0 The y coordinate of the start of the line.
x2number <optional>
0 The x coordinate of the end of the line.
y2number <optional>
0 The y coordinate of the end of the line.
- Source:
Returns:
This line object
- Type
- Phaser.Line