Phaser API Documentation

  Version: 
Filter
Namespace: Intersects
Phaser.Geom.Intersects

Methods

<static> CircleToCircle(circleA, circleB)
Focus
Focus

Description:

Checks if two Circles intersect.

Parameters:

name type description
circleA Phaser.Geom.Circle

The first Circle to check for intersection.

circleB Phaser.Geom.Circle

The second Circle to check for intersection.

Returns:
Description:

true if the two Circles intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> CircleToRectangle(circle, rect)
Focus
Focus

Description:

Checks for intersection between a circle and a rectangle.

Parameters:

name type description
circle Phaser.Geom.Circle

The circle to be checked.

rect Phaser.Geom.Rectangle

The rectangle to be checked.

Returns:
Description:

true if the two objects intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> GetCircleToCircle(circleA, circleB, [out])
Focus
Focus

Description:

Checks if two Circles intersect and returns the intersection points as a Point object array.

Parameters:

name type arguments description
circleA Phaser.Geom.Circle

The first Circle to check for intersection.

circleB Phaser.Geom.Circle

The second Circle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Since: 3.0.0
Focus
Focus
<static> GetCircleToRectangle(circle, rect, [out])
Focus
Focus

Description:

Checks for intersection between a circle and a rectangle, and returns the intersection points as a Point object array.

Parameters:

name type arguments description
circle Phaser.Geom.Circle

The circle to be checked.

rect Phaser.Geom.Rectangle

The rectangle to be checked.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Since: 3.0.0
Focus
Focus
<static> GetLineToCircle(line, circle, [out])
Focus
Focus

Description:

Checks for intersection between the line segment and circle, and returns the intersection points as a Point object array.

Parameters:

name type arguments description
line Phaser.Geom.Line

The line segment to check.

circle Phaser.Geom.Circle

The circle to check against the line.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Since: 3.0.0
Focus
Focus
<static> GetLineToLine(line1, line2, [out])
Focus
Focus

Description:

Checks for intersection between the two line segments and returns the intersection point as a Vector3, or null if the lines are parallel, or do not intersect.

The z property of the Vector3 contains the intersection distance, which can be used to find the closest intersecting point from a group of line segments.

Parameters:

name type arguments description
line1 Phaser.Geom.Line

The first line segment to check.

line2 Phaser.Geom.Line

The second line segment to check.

out Phaser.Math.Vector3 <optional>

A Vector3 to store the intersection results in.

Returns:
Description:

A Vector3 containing the intersection results, or null.

Since: 3.50.0
Focus
Focus
<static> GetLineToPoints(line, points, [out])
Focus
Focus

Description:

Checks for the closest point of intersection between a line segment and an array of points, where each pair of points are converted to line segments for the intersection tests.

If no intersection is found, this function returns null.

If intersection was found, a Vector3 is returned with the following properties:

The x and y components contain the point of the intersection. The z component contains the closest distance.

Parameters:

name type arguments description
line Phaser.Geom.Line

The line segment to check.

points Array.<Phaser.Math.Vector2> | Array.<Phaser.Geom.Point>

An array of points to check.

out Phaser.Math.Vector3 <optional>

A Vector3 to store the intersection results in.

Returns:
Description:

A Vector3 containing the intersection results, or null.

Since: 3.50.0
Focus
Focus
<static> GetLineToPolygon(line, polygons, [out])
Focus
Focus

Description:

Checks for the closest point of intersection between a line segment and an array of polygons.

If no intersection is found, this function returns null.

If intersection was found, a Vector4 is returned with the following properties:

The x and y components contain the point of the intersection. The z component contains the closest distance. The w component contains the index of the polygon, in the given array, that triggered the intersection.

Parameters:

name type arguments description
line Phaser.Geom.Line

The line segment to check.

polygons Phaser.Geom.Polygon | Array.<Phaser.Geom.Polygon>

A single polygon, or array of polygons, to check.

out Phaser.Math.Vector4 <optional>

A Vector4 to store the intersection results in.

Returns:
Description:

A Vector4 containing the intersection results, or null.

Since: 3.50.0
Focus
Focus
<static> GetLineToRectangle(line, rect, [out])
Focus
Focus

Description:

Checks for intersection between the Line and a Rectangle shape, and returns the intersection points as a Point object array.

Parameters:

name type arguments description
line Phaser.Geom.Line

The Line to check for intersection.

rect object | Phaser.Geom.Rectangle

The Rectangle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Since: 3.0.0
Focus
Focus
<static> GetRaysFromPointToPolygon(x, y, polygons)
Focus
Focus

Description:

Projects rays out from the given point to each line segment of the polygons.

If the rays intersect with the polygons, the points of intersection are returned in an array.

If no intersections are found, the returned array will be empty.

Each Vector4 intersection result has the following properties:

The x and y components contain the point of the intersection. The z component contains the angle of intersection. The w component contains the index of the polygon, in the given array, that triggered the intersection.

Parameters:

name type description
x number

The x coordinate to project the rays from.

y number

The y coordinate to project the rays from.

polygons Phaser.Geom.Polygon | Array.<Phaser.Geom.Polygon>

A single polygon, or array of polygons, to check against the rays.

Returns:
Description:

An array containing all intersections in Vector4s.

Type:
Focus
Focus
<static> GetRectangleIntersection(rectA, rectB, [output])
Focus
Focus

Description:

Checks if two Rectangle shapes intersect and returns the area of this intersection as Rectangle object.

If optional output parameter is omitted, new Rectangle object is created and returned. If there is intersection, it will contain intersection area. If there is no intersection, it wil be empty Rectangle (all values set to zero).

If Rectangle object is passed as output and there is intersection, then intersection area data will be loaded into it and it will be returned. If there is no intersection, it will be returned without any change.

Parameters:

name type arguments description
rectA Phaser.Geom.Rectangle

The first Rectangle object.

rectB Phaser.Geom.Rectangle

The second Rectangle object.

output Phaser.Geom.Rectangle <optional>

Optional Rectangle object. If given, the intersection data will be loaded into it (in case of no intersection, it will be left unchanged). Otherwise, new Rectangle object will be created and returned with either intersection data or empty (all values set to zero), if there is no intersection.

Returns:
Description:

A rectangle object with intersection data.

Focus
Focus
<static> GetRectangleToRectangle(rectA, rectB, [out])
Focus
Focus

Description:

Checks if two Rectangles intersect and returns the intersection points as a Point object array.

A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. As such, the two Rectangles are considered "solid". A Rectangle with no width or no height will never intersect another Rectangle.

Parameters:

name type arguments description
rectA Phaser.Geom.Rectangle

The first Rectangle to check for intersection.

rectB Phaser.Geom.Rectangle

The second Rectangle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Focus
Focus
<static> GetRectangleToTriangle(rect, triangle, [out])
Focus
Focus

Description:

Checks for intersection between Rectangle shape and Triangle shape, and returns the intersection points as a Point object array.

Parameters:

name type arguments description
rect Phaser.Geom.Rectangle

Rectangle object to test.

triangle Phaser.Geom.Triangle

Triangle object to test.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Focus
Focus
<static> GetTriangleToCircle(triangle, circle, [out])
Focus
Focus

Description:

Checks if a Triangle and a Circle intersect, and returns the intersection points as a Point object array.

A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection.

Parameters:

name type arguments description
triangle Phaser.Geom.Triangle

The Triangle to check for intersection.

circle Phaser.Geom.Circle

The Circle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Since: 3.0.0
Focus
Focus
<static> GetTriangleToLine(triangle, line, [out])
Focus
Focus

Description:

Checks if a Triangle and a Line intersect, and returns the intersection points as a Point object array.

The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid".

Parameters:

name type arguments description
triangle Phaser.Geom.Triangle

The Triangle to check with.

line Phaser.Geom.Line

The Line to check with.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Since: 3.0.0
Focus
Focus
<static> GetTriangleToTriangle(triangleA, triangleB, [out])
Focus
Focus

Description:

Checks if two Triangles intersect, and returns the intersection points as a Point object array.

A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid".

Parameters:

name type arguments description
triangleA Phaser.Geom.Triangle

The first Triangle to check for intersection.

triangleB Phaser.Geom.Triangle

The second Triangle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Returns:
Description:

An array with the points of intersection if objects intersect, otherwise an empty array.

Type:
  • array
Since: 3.0.0
Focus
Focus
<static> LineToCircle(line, circle, [nearest])
Focus
Focus

Description:

Checks for intersection between the line segment and circle.

Based on code by Matt DesLauriers.

Parameters:

name type arguments description
line Phaser.Geom.Line

The line segment to check.

circle Phaser.Geom.Circle

The circle to check against the line.

nearest any | Phaser.Geom.Point <optional>

An optional Point-like object. If given the closest point on the Line where the circle intersects will be stored in this object.

Returns:
Description:

true if the two objects intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> LineToLine(line1, line2, [out])
Focus
Focus

Description:

Checks if two Lines intersect. If the Lines are identical, they will be treated as parallel and thus non-intersecting.

Parameters:

name type arguments description
line1 Phaser.Geom.Line

The first Line to check.

line2 Phaser.Geom.Line

The second Line to check.

out Phaser.Geom.Point <optional>

A Point in which to optionally store the point of intersection.

Returns:
Description:

true if the two Lines intersect, and the out object will be populated, if given. Otherwise, false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> LineToRectangle(line, rect)
Focus
Focus

Description:

Checks for intersection between the Line and a Rectangle shape, or a rectangle-like object, with public x, y, right and bottom properties, such as a Sprite or Body.

An intersection is considered valid if:

The line starts within, or ends within, the Rectangle. The line segment intersects one of the 4 rectangle edges.

The for the purposes of this function rectangles are considered 'solid'.

Parameters:

name type description
line Phaser.Geom.Line

The Line to check for intersection.

rect object | Phaser.Geom.Rectangle

The Rectangle to check for intersection.

Returns:
Description:

true if the Line and the Rectangle intersect, false otherwise.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> PointToLine(point, line, [lineThickness])
Focus
Focus

Description:

Checks if the a Point falls between the two end-points of a Line, based on the given line thickness.

Assumes that the line end points are circular, not square.

Parameters:

name type arguments Default description
point any | Phaser.Geom.Point

The point, or point-like object to check.

line Phaser.Geom.Line

The line segment to test for intersection on.

lineThickness number <optional> 1

The line thickness. Assumes that the line end points are circular.

Returns:
Description:

true if the Point falls on the Line, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> PointToLineSegment(point, line)
Focus
Focus

Description:

Checks if a Point is located on the given line segment.

Parameters:

name type description
point Phaser.Geom.Point

The Point to check for intersection.

line Phaser.Geom.Line

The line segment to check for intersection.

Returns:
Description:

true if the Point is on the given line segment, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> RectangleToRectangle(rectA, rectB)
Focus
Focus

Description:

Checks if two Rectangles intersect.

A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. As such, the two Rectangles are considered "solid". A Rectangle with no width or no height will never intersect another Rectangle.

Parameters:

name type description
rectA Phaser.Geom.Rectangle

The first Rectangle to check for intersection.

rectB Phaser.Geom.Rectangle

The second Rectangle to check for intersection.

Returns:
Description:

true if the two Rectangles intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> RectangleToTriangle(rect, triangle)
Focus
Focus

Description:

Checks for intersection between Rectangle shape and Triangle shape.

Parameters:

name type description
rect Phaser.Geom.Rectangle

Rectangle object to test.

triangle Phaser.Geom.Triangle

Triangle object to test.

Returns:
Description:

A value of true if objects intersect; otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> RectangleToValues(rect, left, right, top, bottom, [tolerance])
Focus
Focus

Description:

Check if rectangle intersects with values.

Parameters:

name type arguments description
rect Phaser.Geom.Rectangle

The rectangle object

left number

The x coordinate of the left of the Rectangle.

right number

The x coordinate of the right of the Rectangle.

top number

The y coordinate of the top of the Rectangle.

bottom number

The y coordinate of the bottom of the Rectangle.

tolerance number <optional>

Tolerance allowed in the calculation, expressed in pixels.

Returns:
Description:

Returns true if there is an intersection.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> TriangleToCircle(triangle, circle)
Focus
Focus

Description:

Checks if a Triangle and a Circle intersect.

A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection.

Parameters:

name type description
triangle Phaser.Geom.Triangle

The Triangle to check for intersection.

circle Phaser.Geom.Circle

The Circle to check for intersection.

Returns:
Description:

true if the Triangle and the Circle intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> TriangleToLine(triangle, line)
Focus
Focus

Description:

Checks if a Triangle and a Line intersect.

The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid".

Parameters:

name type description
triangle Phaser.Geom.Triangle

The Triangle to check with.

line Phaser.Geom.Line

The Line to check with.

Returns:
Description:

true if the Triangle and the Line intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> TriangleToTriangle(triangleA, triangleB)
Focus
Focus

Description:

Checks if two Triangles intersect.

A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid".

Parameters:

name type description
triangleA Phaser.Geom.Triangle

The first Triangle to check for intersection.

triangleB Phaser.Geom.Triangle

The second Triangle to check for intersection.

Returns:
Description:

true if the Triangles intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus