Encapsulates a 2D rectangle defined by its corner point in the top-left and its extends in x (width) and y (height)
new Rectangle([x], [y], [width], [height])
name | type | arguments | description |
---|---|---|---|
x | number | <optional> |
The X coordinate of the top left corner of the Rectangle. |
y | number | <optional> |
The Y coordinate of the top left corner of the Rectangle. |
width | number | <optional> |
The width of the Rectangle. |
height | number | <optional> |
The height of the Rectangle. |
The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
The x coordinate of the center of the Rectangle.
The y coordinate of the center of the Rectangle.
The height of the Rectangle, i.e. the distance between its top side (defined by y
) and its bottom side.
The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties, however it does affect the width property.
The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. However it does affect the height property, whereas changing the y value does not affect the height property.
The geometry constant type of this object: GEOM_CONST.RECTANGLE
.
Used for fast type comparisons.
The width of the Rectangle, i.e. the distance between its left side (defined by x
) and its right side.
The X coordinate of the top left corner of the Rectangle.
The Y coordinate of the top left corner of the Rectangle.
Checks if the given point is inside the Rectangle's bounds.
name | type | description |
---|---|---|
x | number |
The X coordinate of the point to check. |
y | number |
The Y coordinate of the point to check. |
true
if the point is within the Rectangle's bounds, otherwise false
.
Returns a Line object that corresponds to the top of this Rectangle.
name | type | arguments | description |
---|---|---|---|
line | Phaser.Geom.Line | <optional> |
A Line object to set the results in. If |
A Line object that corresponds to the top of this Rectangle.
Returns a Line object that corresponds to the right of this Rectangle.
name | type | arguments | description |
---|---|---|---|
line | Phaser.Geom.Line | <optional> |
A Line object to set the results in. If |
A Line object that corresponds to the right of this Rectangle.
Returns a Line object that corresponds to the bottom of this Rectangle.
name | type | arguments | description |
---|---|---|---|
line | Phaser.Geom.Line | <optional> |
A Line object to set the results in. If |
A Line object that corresponds to the bottom of this Rectangle.
Returns a Line object that corresponds to the left of this Rectangle.
name | type | arguments | description |
---|---|---|---|
line | Phaser.Geom.Line | <optional> |
A Line object to set the results in. If |
A Line object that corresponds to the left of this Rectangle.
Calculates the coordinates of a point at a certain position
on the Rectangle's perimeter.
The position
is a fraction between 0 and 1 which defines how far into the perimeter the point is.
A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side.
name | type | arguments | description |
---|---|---|---|
position | number |
The normalized distance into the Rectangle's perimeter to return. |
|
output | object | Phaser.Geom.Point | <optional> |
An object to update with the |
The updated output
object, or a new Point if no output
object was given.
Returns an array of points from the perimeter of the Rectangle, each spaced out based on the quantity or step required.
name | type | arguments | description |
---|---|---|---|
quantity | number |
The number of points to return. Set to |
|
stepRate | number | <optional> |
If |
output | array | Array.<Phaser.Geom.Point> | <optional> |
An array to which to append the points. |
The modified output
array, or a new array if none was provided.
Returns a random point within the Rectangle's bounds.
name | type | arguments | description |
---|---|---|---|
point | Phaser.Geom.Point | <optional> |
The object in which to store the |
The updated point
, or a new Point if none was provided.
Determines if the Rectangle is empty. A Rectangle is empty if its width or height is less than or equal to 0.
true
if the Rectangle is empty. A Rectangle object is empty if its width or height is less than or equal to 0.
Resets the position, width, and height of the Rectangle to 0.
This Rectangle object.
Sets the position of the Rectangle.
name | type | arguments | Default | description |
---|---|---|---|---|
x | number |
The X coordinate of the top left corner of the Rectangle. |
||
y | number | <optional> | x |
The Y coordinate of the top left corner of the Rectangle. |
This Rectangle object.
Sets the width and height of the Rectangle.
name | type | arguments | Default | description |
---|---|---|---|---|
width | number |
The width to set the Rectangle to. |
||
height | number | <optional> | width |
The height to set the Rectangle to. |
This Rectangle object.
Sets the position, width, and height of the Rectangle.
name | type | description |
---|---|---|
x | number |
The X coordinate of the top left corner of the Rectangle. |
y | number |
The Y coordinate of the top left corner of the Rectangle. |
width | number |
The width of the Rectangle. |
height | number |
The height of the Rectangle. |
This Rectangle object.
Calculates the area of the given Rectangle object.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The rectangle to calculate the area of. |
The area of the Rectangle object.
Rounds a Rectangle's position up to the smallest integer greater than or equal to each current coordinate.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to adjust. |
The adjusted Rectangle.
Rounds a Rectangle's position and size up to the smallest integer greater than or equal to each respective value.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to modify. |
The modified Rectangle.
Moves the top-left corner of a Rectangle so that its center is at the given coordinates.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to be centered. |
x | number |
The X coordinate of the Rectangle's center. |
y | number |
The Y coordinate of the Rectangle's center. |
The centered rectangle.
Creates a new Rectangle which is identical to the given one.
name | type | description |
---|---|---|
source | Phaser.Geom.Rectangle |
The Rectangle to clone. |
The newly created Rectangle, which is separate from the given one.
Checks if a given point is inside a Rectangle's bounds.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to check. |
x | number |
The X coordinate of the point to check. |
y | number |
The Y coordinate of the point to check. |
true
if the point is within the Rectangle's bounds, otherwise false
.
Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle object. |
point | Phaser.Geom.Point |
The point object to be checked. Can be a Phaser Point object or any object with x and y values. |
A value of true if the Rectangle object contains the specified point, otherwise false.
Tests if one rectangle fully contains another.
name | type | description |
---|---|---|
rectA | Phaser.Geom.Rectangle |
The first rectangle. |
rectB | Phaser.Geom.Rectangle |
The second rectangle. |
True only if rectA fully contains rectB.
Copy the values of one Rectangle to a destination Rectangle.
name | type | description |
---|---|---|
source | Phaser.Geom.Rectangle |
The source Rectangle to copy the values from. |
dest | Phaser.Geom.Rectangle |
The destination Rectangle to copy the values to. |
The destination Rectangle.
Create an array of points for each corner of a Rectangle If an array is specified, each point object will be added to the end of the array, otherwise a new array will be created.
name | type | arguments | description |
---|---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle object to be decomposed. |
|
out | array | <optional> |
If provided, each point will be added to this array. |
Will return the array you specified or a new array containing the points of the Rectangle.
Compares the x
, y
, width
and height
properties of two rectangles.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
Rectangle A |
toCompare | Phaser.Geom.Rectangle |
Rectangle B |
true
if the rectangles' properties are an exact match, otherwise false
.
Adjusts the target rectangle, changing its width, height and position, so that it fits inside the area of the source rectangle, while maintaining its original aspect ratio.
Unlike the FitOutside
function, there may be some space inside the source area not covered.
name | type | description |
---|---|---|
target | Phaser.Geom.Rectangle |
The target rectangle to adjust. |
source | Phaser.Geom.Rectangle |
The source rectangle to envelop the target in. |
The modified target rectangle instance.
Adjusts the target rectangle, changing its width, height and position, so that it fully covers the area of the source rectangle, while maintaining its original aspect ratio.
Unlike the FitInside
function, the target rectangle may extend further out than the source.
name | type | description |
---|---|---|
target | Phaser.Geom.Rectangle |
The target rectangle to adjust. |
source | Phaser.Geom.Rectangle |
The source rectangle to envelope the target in. |
The modified target rectangle instance.
Rounds down (floors) the top left X and Y coordinates of the given Rectangle to the largest integer less than or equal to them
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The rectangle to floor the top left X and Y coordinates of |
The rectangle that was passed to this function with its coordinates floored.
Rounds a Rectangle's position and size down to the largest integer less than or equal to each current coordinate or dimension.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to adjust. |
The adjusted Rectangle.
Constructs new Rectangle or repositions and resizes an existing Rectangle so that all of the given points are on or within its bounds.
The points
parameter is an array of Point-like objects:
const points = [
[100, 200],
[200, 400],
{ x: 30, y: 60 }
]
name | type | arguments | description |
---|---|---|---|
points | array |
An array of points (either arrays with two elements corresponding to the X and Y coordinate or an object with public |
|
out | Phaser.Geom.Rectangle | <optional> |
Optional Rectangle to adjust. |
The adjusted out
Rectangle, or a new Rectangle if none was provided.
Create the smallest Rectangle containing two coordinate pairs.
name | type | arguments | description |
---|---|---|---|
x1 | number |
The X coordinate of the first point. |
|
y1 | number |
The Y coordinate of the first point. |
|
x2 | number |
The X coordinate of the second point. |
|
y2 | number |
The Y coordinate of the second point. |
|
out | Phaser.Geom.Rectangle | <optional> |
Optional Rectangle to adjust. |
The adjusted out
Rectangle, or a new Rectangle if none was provided.
Calculates the width/height ratio of a rectangle.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The rectangle. |
The width/height ratio of the rectangle.
Returns the center of a Rectangle as a Point.
name | type | arguments | description |
---|---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to get the center of. |
|
out | object | Phaser.Geom.Point | <optional> |
Optional point-like object to update with the center coordinates. |
The modified out
object, or a new Point if none was provided.
Calculates the coordinates of a point at a certain position
on the Rectangle's perimeter.
The position
is a fraction between 0 and 1 which defines how far into the perimeter the point is.
A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side.
name | type | arguments | description |
---|---|---|---|
rectangle | Phaser.Geom.Rectangle |
The Rectangle to get the perimeter point from. |
|
position | number |
The normalized distance into the Rectangle's perimeter to return. |
|
out | object | Phaser.Geom.Point | <optional> |
An object to update with the |
The updated output
object, or a new Point if no output
object was given.
Return an array of points from the perimeter of the rectangle, each spaced out based on the quantity or step required.
name | type | arguments | description |
---|---|---|---|
rectangle | Phaser.Geom.Rectangle |
The Rectangle object to get the points from. |
|
step | number |
Step between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive. |
|
quantity | number |
The number of evenly spaced points from the rectangles perimeter to return. If falsey, step param will be used to calculate the number of points. |
|
out | array | Array.<Phaser.Geom.Point> | <optional> |
An optional array to store the points in. |
An array of Points from the perimeter of the rectangle.
Returns the size of the Rectangle, expressed as a Point object.
With the value of the width
as the x
property and the height
as the y
property.
name | type | arguments | description |
---|---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to get the size from. |
|
out | object | Phaser.Geom.Point | <optional> |
The Point object to store the size in. If not given, a new Point instance is created. |
A Point object where x
holds the width and y
holds the height of the Rectangle.
Increases the size of a Rectangle by a specified amount.
The center of the Rectangle stays the same. The amounts are added to each side, so the actual increase in width or height is two times bigger than the respective argument.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to inflate. |
x | number |
How many pixels the left and the right side should be moved by horizontally. |
y | number |
How many pixels the top and the bottom side should be moved by vertically. |
The inflated Rectangle.
Takes two Rectangles and first checks to see if they intersect.
If they intersect it will return the area of intersection in the out
Rectangle.
If they do not intersect, the out
Rectangle will have a width and height of zero.
name | type | arguments | description |
---|---|---|---|
rectA | Phaser.Geom.Rectangle |
The first Rectangle to get the intersection from. |
|
rectB | Phaser.Geom.Rectangle |
The second Rectangle to get the intersection from. |
|
out | Phaser.Geom.Rectangle | <optional> |
A Rectangle to store the intersection results in. |
The intersection result. If the width and height are zero, no intersection occurred.
Returns an array of points from the perimeter of the Rectangle, where each point is spaced out based
on either the step
value, or the quantity
.
name | type | arguments | description |
---|---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to get the perimeter points from. |
|
step | number | <optional> |
The distance between each point of the perimeter. Set to |
quantity | number | <optional> |
The total number of points to return. The step is then calculated based on the length of the Rectangle, divided by this value. |
out | array | Array.<Phaser.Geom.Point> | <optional> |
An array in which the perimeter points will be stored. If not given, a new array instance is created. |
An array containing the perimeter points from the Rectangle.
Merges a Rectangle with a list of points by repositioning and/or resizing it such that all points are located on or within its bounds.
name | type | description |
---|---|---|
target | Phaser.Geom.Rectangle |
The Rectangle which should be merged. |
points | Array.<Phaser.Geom.Point> |
An array of Points (or any object with public |
The modified Rectangle.
Merges the source rectangle into the target rectangle and returns the target. Neither rectangle should have a negative width or height.
name | type | description |
---|---|---|
target | Phaser.Geom.Rectangle |
Target rectangle. Will be modified to include source rectangle. |
source | Phaser.Geom.Rectangle |
Rectangle that will be merged into target rectangle. |
Modified target rectangle that contains source rectangle.
Merges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds.
name | type | description |
---|---|---|
target | Phaser.Geom.Rectangle |
The Rectangle which should be merged and modified. |
x | number |
The X coordinate of the point which should be merged. |
y | number |
The Y coordinate of the point which should be merged. |
The modified target
Rectangle.
Nudges (translates) the top left corner of a Rectangle by a given offset.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to adjust. |
x | number |
The distance to move the Rectangle horizontally. |
y | number |
The distance to move the Rectangle vertically. |
The adjusted Rectangle.
Nudges (translates) the top-left corner of a Rectangle by the coordinates of a point (translation vector).
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to adjust. |
point | Phaser.Geom.Point | Phaser.Math.Vector2 |
The point whose coordinates should be used as an offset. |
The adjusted Rectangle.
Checks if two Rectangles overlap. If a Rectangle is within another Rectangle, the two will be considered overlapping. Thus, the Rectangles are treated as "solid".
name | type | description |
---|---|---|
rectA | Phaser.Geom.Rectangle |
The first Rectangle to check. |
rectB | Phaser.Geom.Rectangle |
The second Rectangle to check. |
true
if the two Rectangles overlap, false
otherwise.
Calculates the perimeter of a Rectangle.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to use. |
The perimeter of the Rectangle, equal to (width * 2) + (height * 2)
.
Returns a Point from the perimeter of a Rectangle based on the given angle.
name | type | arguments | description |
---|---|---|---|
rectangle | Phaser.Geom.Rectangle |
The Rectangle to get the perimeter point from. |
|
angle | number |
The angle of the point, in degrees. |
|
out | Phaser.Geom.Point | <optional> |
The Point object to store the position in. If not given, a new Point instance is created. |
A Point object holding the coordinates of the Rectangle perimeter.
Returns a random point within a Rectangle.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The Rectangle to return a point from. |
out | Phaser.Geom.Point |
The object to update with the point's coordinates. |
The modified out
object, or a new Point if none was provided.
Calculates a random point that lies within the outer
Rectangle, but outside of the inner
Rectangle.
The inner Rectangle must be fully contained within the outer rectangle.
name | type | arguments | description |
---|---|---|---|
outer | Phaser.Geom.Rectangle |
The outer Rectangle to get the random point within. |
|
inner | Phaser.Geom.Rectangle |
The inner Rectangle to exclude from the returned point. |
|
out | Phaser.Geom.Point | <optional> |
A Point, or Point-like object to store the result in. If not specified, a new Point will be created. |
A Point object containing the random values in its x
and y
properties.
Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The first Rectangle object. |
toCompare | Phaser.Geom.Rectangle |
The second Rectangle object. |
true
if the objects have equivalent values for the width
and height
properties, otherwise false
.
Scales the width and height of this Rectangle by the given amounts.
name | type | description |
---|---|---|
rect | Phaser.Geom.Rectangle |
The |
x | number |
The factor by which to scale the rectangle horizontally. |
y | number |
The amount by which to scale the rectangle vertically. If this is not specified, the rectangle will be scaled by the factor |
The rectangle object with updated width
and height
properties as calculated from the scaling factor(s).
Creates a new Rectangle or repositions and/or resizes an existing Rectangle so that it encompasses the two given Rectangles, i.e. calculates their union.
name | type | arguments | description |
---|---|---|---|
rectA | Phaser.Geom.Rectangle |
The first Rectangle to use. |
|
rectB | Phaser.Geom.Rectangle |
The second Rectangle to use. |
|
out | Phaser.Geom.Rectangle | <optional> |
The Rectangle to store the union in. |
The modified out
Rectangle, or a new Rectangle if none was provided.