Optionalx: number
The X coordinate of the top left corner of the Rectangle. Default 0.
Optionaly: number
The Y coordinate of the top left corner of the Rectangle. Default 0.
Optionalwidth: number
The width of the Rectangle. Default 0.
Optionalheight: number
The height of the Rectangle. Default 0.
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.
ReadonlytypeThe 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.
The X coordinate of the point to check.
The Y coordinate of the point to check.
true if the point is within the Rectangle's bounds, otherwise false.
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.
The normalized distance into the Rectangle's perimeter to return.
Optionaloutput: O
A Vector2 instance to update with the x and y coordinates of the point.
The updated output object, or a new Vector2 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.
The number of points to return. Set to false or 0 to return an arbitrary number of points (perimeter / stepRate) evenly spaced around the Rectangle based on the stepRate.
OptionalstepRate: number
If quantity is 0, determines the normalized distance between each returned point.
Optionaloutput: O
An array to which to append the points.
The modified output array, or a new array 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.undefined
true if the Rectangle is empty, otherwise false.
Resets the position, width, and height of the Rectangle to 0.undefined
This Rectangle object.
Sets the position of the Rectangle.
The X coordinate of the top left corner of the Rectangle.
Optionaly: number
The Y coordinate of the top left corner of the Rectangle. Default x.
This Rectangle object.
Sets the width and height of the Rectangle.
The width to set the Rectangle to.
Optionalheight: number
The height to set the Rectangle to. Default width.
This Rectangle object.
Sets the position, width, and height of the Rectangle.
The X coordinate of the top left corner of the Rectangle.
The Y coordinate of the top left corner of the Rectangle.
The width of the Rectangle.
The height of the Rectangle.
This Rectangle object.
StaticAreaCalculates the area of the given Rectangle object.
The rectangle to calculate the area of.
The area of the Rectangle object.
StaticCeilStaticCeilStaticCenterMoves the top-left corner of a Rectangle so that its center is at the given coordinates.
The Rectangle to be centered.
The X coordinate of the Rectangle's center.
The Y coordinate of the Rectangle's center.
The centered rectangle.
StaticCloneStaticContainsChecks if a given point is inside a Rectangle's bounds.
The Rectangle to check.
The X coordinate of the point to check.
The Y coordinate of the point to check.
true if the point is within the Rectangle's bounds, otherwise false.
StaticContainsDetermines whether the specified point is contained within the rectangular region defined by this Rectangle object.
A value of true if the Rectangle object contains the specified point, otherwise false.
StaticContainsTests if one rectangle fully contains another. A rectangle is considered fully contained if all four of its edges (left, right, top, and bottom) lie strictly within the bounds of the outer rectangle. Rectangles that merely touch or overlap are not considered contained.
True only if rectA fully contains rectB.
StaticCopyStaticDecomposeCreates an array of plain {x, y} point objects for each of the four corners of a Rectangle, in the order: top-left, top-right, bottom-right, bottom-left.
If an output array is provided, each point object will be pushed to the end of it, otherwise a new array will be created and returned.
The Rectangle object to be decomposed.
Optionalout: any[]
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.
StaticEqualsCompares the x, y, width and height properties of two rectangles.
Returns true only if all four values match exactly using strict equality.
This function does not consider rectangles with the same area but different
positions or dimensions to be equal.
true if the rectangles' properties are an exact match, otherwise false.
StaticFitAdjusts 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.
The modified target rectangle instance.
StaticFitAdjusts 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.
The modified target rectangle instance.
StaticFloorRounds down (floors) the top left X and Y coordinates of the given Rectangle to the largest integer less than or equal to them
The rectangle to floor the top left X and Y coordinates of
The rectangle that was passed to this function with its coordinates floored.
StaticFloorStaticFromConstructs a 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 }
]
An array of points (either arrays with two elements corresponding to the X and Y coordinate or an object with public x and y properties) which should be surrounded by the Rectangle.
Optionalout: O
Optional Rectangle to adjust.
The adjusted out Rectangle, or a new Rectangle if none was provided.
StaticFromCreate the smallest Rectangle containing two coordinate pairs.
The X coordinate of the first point.
The Y coordinate of the first point.
The X coordinate of the second point.
The Y coordinate of the second point.
Optionalout: O
Optional Rectangle to adjust.
The adjusted out Rectangle, or a new Rectangle if none was provided.
StaticGetCalculates the width/height ratio of a rectangle.
The rectangle.
The width/height ratio of the rectangle.
StaticGetStaticGetCalculates 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.
The updated out object, or a new Vector2 if no out object was given.
StaticGetReturn an array of Vector2 points from the perimeter of the rectangle, each spaced out based on the quantity or step required.
The Rectangle object to get the points from.
The number of evenly spaced points from the rectangle's perimeter to return. If falsey, stepRate param will be used to calculate the number of points.
Step between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive.
Optionalout: O
An optional array to store the points in.
An array of Vector2 points from the perimeter of the rectangle.
StaticGetStaticInflateIncreases 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.
The Rectangle to inflate.
How many pixels the left and the right side should be moved by horizontally.
How many pixels the top and the bottom side should be moved by vertically.
The inflated Rectangle.
StaticIntersectionTakes 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.
The intersection result. If the width and height are zero, no intersection occurred.
StaticMarchingReturns an array of Vector2 points evenly distributed around the perimeter of the Rectangle. This is commonly used to create a "marching ants" selection effect, where the returned points are used to animate a dashed outline that appears to march around the border of the rectangle.
You can control the spacing of the points either by providing a pixel step distance between each
point, or by specifying the total quantity of points to distribute evenly around the full perimeter.
If both are omitted, an empty array is returned. If step is provided, quantity is derived from
the perimeter length divided by the step. If only quantity is provided, the step is derived instead.
The Rectangle to get the perimeter points from.
Optionalstep: number
The distance between each point of the perimeter. Set to null if you wish to use the quantity parameter instead.
Optionalquantity: number
The total number of points to return. The step is then calculated based on the length of the Rectangle, divided by this value.
Optionalout: O
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.
StaticMergeStaticMergeStaticMergeMerges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds.
The Rectangle which should be merged and modified.
The X coordinate of the point which should be merged.
The Y coordinate of the point which should be merged.
The modified target Rectangle.
StaticOffsetTranslates a Rectangle by the given horizontal and vertical amounts, moving its position while preserving its size.
The Rectangle to adjust.
The distance to move the Rectangle horizontally.
The distance to move the Rectangle vertically.
The adjusted Rectangle.
StaticOffsetStaticOverlapsChecks if two Rectangles overlap. If a Rectangle is within another Rectangle, the two will be considered overlapping. Thus, the Rectangles are treated as "solid".
true if the two Rectangles overlap, false otherwise.
StaticPerimeterCalculates the perimeter of a Rectangle.
The Rectangle to use.
The perimeter of the Rectangle, equal to (width * 2) + (height * 2).
StaticPerimeterStaticRandomStaticRandomCalculates 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 for a point to be generated.
If inner is not fully contained within outer, the function returns the out vector unchanged.
A Vector2 object containing the random values in its x and y properties.
StaticSameDetermines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.
true if the objects have equivalent values for the width and height properties, otherwise false.
StaticScaleScales the width and height of the given Rectangle by the given factors.
The Rectangle object that will be scaled by the specified amount(s).
The factor by which to scale the rectangle horizontally.
The factor by which to scale the rectangle vertically. If this is not specified, the rectangle will be scaled by the factor x in both directions.
The rectangle object with updated width and height properties as calculated from the scaling factor(s).
StaticUnion
A Rectangle is an axis-aligned region of 2D space defined by its top-left corner position (
x,y) and its dimensions (width,height). It is one of the core geometric primitives in Phaser and is used extensively throughout the framework for bounds checking, camera viewports, hit areas, culling regions, and UI layout.Rectangles support containment tests, perimeter point sampling, and many other geometric operations available via the
Phaser.Geom.Rectanglestatic methods. Theleft,right,top,bottom,centerX, andcenterYproperties provide convenient access to derived positional values and can be set directly to reposition or resize the Rectangle.