Skip to main content
Version: Phaser v4.0.0

Rectangle

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.Rectangle static methods. The left, right, top, bottom, centerX, and centerY properties provide convenient access to derived positional values and can be set directly to reposition or resize the Rectangle.

Constructor

new Rectangle([x], [y], [width], [height])

Parameters

nametypeoptionaldefaultdescription
xnumberYes0The X coordinate of the top left corner of the Rectangle.
ynumberYes0The Y coordinate of the top left corner of the Rectangle.
widthnumberYes0The width of the Rectangle.
heightnumberYes0The height of the Rectangle.

Scope: static

Source: src/geom/rectangle/Rectangle.js#L15
Since: 3.0.0

Public Methods

Area

<static> Area(rect)

Description:

Calculates the area of the given Rectangle object.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe rectangle to calculate the area of.

Returns: number - The area of the Rectangle object.

Source: src/geom/rectangle/Area.js#L7
Since: 3.0.0


Ceil

<static> Ceil(rect)

Description:

Rounds a Rectangle's position up to the smallest integer greater than or equal to each current coordinate.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to adjust.

Returns: Phaser.Geom.Rectangle - The adjusted Rectangle.

Source: src/geom/rectangle/Ceil.js#L7
Since: 3.0.0


CeilAll

<static> CeilAll(rect)

Description:

Rounds a Rectangle's position and size up to the smallest integer greater than or equal to each respective value.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to modify.

Returns: Phaser.Geom.Rectangle - The modified Rectangle.

Source: src/geom/rectangle/CeilAll.js#L7
Since: 3.0.0


CenterOn

<static> CenterOn(rect, x, y)

Description:

Moves the top-left corner of a Rectangle so that its center is at the given coordinates.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to be centered.
xnumberNoThe X coordinate of the Rectangle's center.
ynumberNoThe Y coordinate of the Rectangle's center.

Returns: Phaser.Geom.Rectangle - The centered rectangle.

Source: src/geom/rectangle/CenterOn.js#L7
Since: 3.0.0


Clone

<static> Clone(source)

Description:

Creates a new Rectangle which is identical to the given one.

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.RectangleNoThe Rectangle to clone.

Returns: Phaser.Geom.Rectangle - The newly created Rectangle, which is separate from the given one.

Source: src/geom/rectangle/Clone.js#L9
Since: 3.0.0


contains

<instance> contains(x, y)

Description:

Checks if the given point is inside the Rectangle's bounds.

Parameters:

nametypeoptionaldescription
xnumberNoThe X coordinate of the point to check.
ynumberNoThe Y coordinate of the point to check.

Returns: boolean - true if the point is within the Rectangle's bounds, otherwise false.

Source: src/geom/rectangle/Rectangle.js#L99
Since: 3.0.0


Contains

<static> Contains(rect, x, y)

Description:

Checks if a given point is inside a Rectangle's bounds.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to check.
xnumberNoThe X coordinate of the point to check.
ynumberNoThe Y coordinate of the point to check.

Returns: boolean - true if the point is within the Rectangle's bounds, otherwise false.

Source: src/geom/rectangle/Contains.js#L7
Since: 3.0.0


ContainsPoint

<static> ContainsPoint(rect, vec)

Description:

Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle object.
vecPhaser.Math.Vector2NoThe Vector2 object to check the coordinates of.

Returns: boolean - A value of true if the Rectangle object contains the specified point, otherwise false.

Source: src/geom/rectangle/ContainsPoint.js#L9
Since: 3.0.0


ContainsRect

<static> ContainsRect(rectA, rectB)

Description:

Tests 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.

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe outer rectangle to test as the container.
rectBPhaser.Geom.RectangleNoThe inner rectangle to test for full containment within rectA.

Returns: boolean - True only if rectA fully contains rectB.

Source: src/geom/rectangle/ContainsRect.js#L7
Since: 3.0.0


CopyFrom

<static> CopyFrom(source, dest)

Description:

Copy the values of one Rectangle to a destination Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.RectangleNoThe source Rectangle to copy the values from.
destPhaser.Geom.RectangleNoThe destination Rectangle to copy the values to.

Returns: Phaser.Geom.Rectangle - The destination Rectangle.

Source: src/geom/rectangle/CopyFrom.js#L7
Since: 3.0.0


Decompose

<static> Decompose(rect, [out])

Description:

Creates 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.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle object to be decomposed.
outarrayYesIf provided, each point will be added to this array.

Returns: array - Will return the array you specified or a new array containing the points of the Rectangle.

Source: src/geom/rectangle/Decompose.js#L7
Since: 3.0.0


Equals

<static> Equals(rect, toCompare)

Description:

Compares 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.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe first rectangle to compare.
toComparePhaser.Geom.RectangleNoThe second rectangle to compare against.

Returns: boolean - true if the rectangles' properties are an exact match, otherwise false.

Source: src/geom/rectangle/Equals.js#L7
Since: 3.0.0


FitInside

<static> FitInside(target, source)

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoThe target rectangle to adjust.
sourcePhaser.Geom.RectangleNoThe source rectangle to envelop the target in.

Returns: Phaser.Geom.Rectangle - The modified target rectangle instance.

Source: src/geom/rectangle/FitInside.js#L9
Since: 3.0.0


FitOutside

<static> FitOutside(target, source)

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoThe target rectangle to adjust.
sourcePhaser.Geom.RectangleNoThe source rectangle to envelope the target in.

Returns: Phaser.Geom.Rectangle - The modified target rectangle instance.

Source: src/geom/rectangle/FitOutside.js#L9
Since: 3.0.0


Floor

<static> Floor(rect)

Description:

Rounds down (floors) the top left X and Y coordinates of the given Rectangle to the largest integer less than or equal to them

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe rectangle to floor the top left X and Y coordinates of

Returns: Phaser.Geom.Rectangle - The rectangle that was passed to this function with its coordinates floored.

Source: src/geom/rectangle/Floor.js#L7
Since: 3.0.0


FloorAll

<static> FloorAll(rect)

Description:

Rounds a Rectangle's position and size down to the largest integer less than or equal to each current coordinate or dimension.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to adjust.

Returns: Phaser.Geom.Rectangle - The adjusted Rectangle.

Source: src/geom/rectangle/FloorAll.js#L7
Since: 3.0.0


FromPoints

<static> FromPoints(points, [out])

Description:

Constructs 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 }

]

Tags:

  • generic

Parameters:

nametypeoptionaldescription
pointsarrayNoAn 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.
outPhaser.Geom.RectangleYesOptional Rectangle to adjust.

Returns: Phaser.Geom.Rectangle - The adjusted out Rectangle, or a new Rectangle if none was provided.

Source: src/geom/rectangle/FromPoints.js#L10
Since: 3.0.0


FromXY

<static> FromXY(x1, y1, x2, y2, [out])

Description:

Create the smallest Rectangle containing two coordinate pairs.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
x1numberNoThe X coordinate of the first point.
y1numberNoThe Y coordinate of the first point.
x2numberNoThe X coordinate of the second point.
y2numberNoThe Y coordinate of the second point.
outPhaser.Geom.RectangleYesOptional Rectangle to adjust.

Returns: Phaser.Geom.Rectangle - The adjusted out Rectangle, or a new Rectangle if none was provided.

Source: src/geom/rectangle/FromXY.js#L9
Since: 3.23.0


GetAspectRatio

<static> GetAspectRatio(rect)

Description:

Calculates the width/height ratio of a rectangle.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe rectangle.

Returns: number - The width/height ratio of the rectangle.

Source: src/geom/rectangle/GetAspectRatio.js#L7
Since: 3.0.0


GetCenter

<static> GetCenter(rect, [out])

Description:

Returns the center of a Rectangle as a Point.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to get the center of.
outPhaser.Math.Vector2YesOptional Vector2 object to update with the center coordinates.

Returns: Phaser.Math.Vector2 - The modified out object, or a new Vector2 if none was provided.

Source: src/geom/rectangle/GetCenter.js#L9
Since: 3.0.0


getLineA

<instance> getLineA([line])

Description:

Returns a Line object that corresponds to the top of this Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineYesA Line object to set the results in. If undefined a new Line will be created.

Returns: Phaser.Geom.Line - A Line object that corresponds to the top of this Rectangle.

Source: src/geom/rectangle/Rectangle.js#L264
Since: 3.0.0


getLineB

<instance> getLineB([line])

Description:

Returns a Line object that corresponds to the right of this Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineYesA Line object to set the results in. If undefined a new Line will be created.

Returns: Phaser.Geom.Line - A Line object that corresponds to the right of this Rectangle.

Source: src/geom/rectangle/Rectangle.js#L285
Since: 3.0.0


getLineC

<instance> getLineC([line])

Description:

Returns a Line object that corresponds to the bottom of this Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineYesA Line object to set the results in. If undefined a new Line will be created.

Returns: Phaser.Geom.Line - A Line object that corresponds to the bottom of this Rectangle.

Source: src/geom/rectangle/Rectangle.js#L306
Since: 3.0.0


getLineD

<instance> getLineD([line])

Description:

Returns a Line object that corresponds to the left of this Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineYesA Line object to set the results in. If undefined a new Line will be created.

Returns: Phaser.Geom.Line - A Line object that corresponds to the left of this Rectangle.

Source: src/geom/rectangle/Rectangle.js#L327
Since: 3.0.0


getPoint

<instance> getPoint(position, [output])

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
positionnumberNoThe normalized distance into the Rectangle's perimeter to return.
outputPhaser.Math.Vector2YesA Vector2 instance to update with the x and y coordinates of the point.

Returns: Phaser.Math.Vector2 - The updated output object, or a new Vector2 if no output object was given.

Source: src/geom/rectangle/Rectangle.js#L115
Since: 3.0.0


GetPoint

<static> GetPoint(rectangle, position, [out])

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectanglePhaser.Geom.RectangleNoThe Rectangle to get the perimeter point from.
positionnumberNoThe normalized distance into the Rectangle's perimeter to return.
outPhaser.Math.Vector2YesA Vector2 object to update with the x and y coordinates of the point.

Returns: Phaser.Math.Vector2 - The updated out object, or a new Vector2 if no out object was given.

Source: src/geom/rectangle/GetPoint.js#L10
Since: 3.0.0


getPoints

<instance> getPoints(quantity, [stepRate], [output])

Description:

Returns an array of points from the perimeter of the Rectangle, each spaced out based on the quantity or step required.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
quantitynumberNoThe 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.
stepRatenumberYesIf quantity is 0, determines the normalized distance between each returned point.
outputArray.<Phaser.Math.Vector2>YesAn array to which to append the points.

Returns: Array.<Phaser.Math.Vector2> - The modified output array, or a new array if none was provided.

Source: src/geom/rectangle/Rectangle.js#L137
Since: 3.0.0


GetPoints

<static> GetPoints(rectangle, quantity, stepRate, [out])

Description:

Return an array of Vector2 points from the perimeter of the rectangle, each spaced out based on the quantity or step required.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectanglePhaser.Geom.RectangleNoThe Rectangle object to get the points from.
quantitynumberNoThe 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.
stepRatenumberNoStep between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive.
outArray.<Phaser.Math.Vector2>YesAn optional array to store the points in.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 points from the perimeter of the rectangle.

Source: src/geom/rectangle/GetPoints.js#L10
Since: 3.0.0


getRandomPoint

<instance> getRandomPoint([vec])

Description:

Returns a random point within the Rectangle's bounds.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
vecPhaser.Math.Vector2YesThe object in which to store the x and y coordinates of the point.

Returns: Phaser.Math.Vector2 - The updated vec, or a new Vector2 if none was provided.

Source: src/geom/rectangle/Rectangle.js#L156
Since: 3.0.0


GetSize

<static> GetSize(rect, [out])

Description:

Returns the size of the Rectangle, expressed as a Vector2 object. With the value of the width as the x property and the height as the y property.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to get the size from.
outPhaser.Math.Vector2YesThe Vector2 object to store the size in. If not given, a new Vector2 instance is created.

Returns: Phaser.Math.Vector2 - A Vector2 object where x holds the width and y holds the height of the Rectangle.

Source: src/geom/rectangle/GetSize.js#L9
Since: 3.0.0


Inflate

<static> Inflate(rect, x, y)

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to inflate.
xnumberNoHow many pixels the left and the right side should be moved by horizontally.
ynumberNoHow many pixels the top and the bottom side should be moved by vertically.

Returns: Phaser.Geom.Rectangle - The inflated Rectangle.

Source: src/geom/rectangle/Inflate.js#L9
Since: 3.0.0


Intersection

<static> Intersection(rectA, rectB, [out])

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to get the intersection from.
rectBPhaser.Geom.RectangleNoThe second Rectangle to get the intersection from.
outPhaser.Geom.RectangleYesA Rectangle to store the intersection results in.

Returns: Phaser.Geom.Rectangle - The intersection result. If the width and height are zero, no intersection occurred.

Source: src/geom/rectangle/Intersection.js#L10
Since: 3.11.0


isEmpty

<instance> isEmpty()

Description:

Determines if the Rectangle is empty. A Rectangle is empty if its width or height is less than or equal to 0.

Returns: boolean - true if the Rectangle is empty, otherwise false.

Source: src/geom/rectangle/Rectangle.js#L251
Since: 3.0.0


MarchingAnts

<static> MarchingAnts(rect, [step], [quantity], [out])

Description:

Returns 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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to get the perimeter points from.
stepnumberYesThe distance between each point of the perimeter. Set to null if you wish to use the quantity parameter instead.
quantitynumberYesThe total number of points to return. The step is then calculated based on the length of the Rectangle, divided by this value.
outArray.<Phaser.Math.Vector2>YesAn array in which the perimeter points will be stored. If not given, a new array instance is created.

Returns: Array.<Phaser.Math.Vector2> - An array containing the perimeter points from the Rectangle.

Source: src/geom/rectangle/MarchingAnts.js#L10
Since: 3.0.0


MergePoints

<static> MergePoints(target, points)

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoThe Rectangle which should be merged.
pointsArray.<Phaser.Math.Vector2>NoAn array of Vector2 objects which should be merged with the Rectangle.

Returns: Phaser.Geom.Rectangle - The modified Rectangle.

Source: src/geom/rectangle/MergePoints.js#L7
Since: 3.0.0


MergeRect

<static> MergeRect(target, source)

Description:

Merges the source rectangle into the target rectangle and returns the target. Neither rectangle should have a negative width or height.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoTarget rectangle. Will be modified to include source rectangle.
sourcePhaser.Geom.RectangleNoRectangle that will be merged into target rectangle.

Returns: Phaser.Geom.Rectangle - Modified target rectangle that contains source rectangle.

Source: src/geom/rectangle/MergeRect.js#L7
Since: 3.0.0


MergeXY

<static> MergeXY(target, x, y)

Description:

Merges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoThe Rectangle which should be merged and modified.
xnumberNoThe X coordinate of the point which should be merged.
ynumberNoThe Y coordinate of the point which should be merged.

Returns: Phaser.Geom.Rectangle - The modified target Rectangle.

Source: src/geom/rectangle/MergeXY.js#L7
Since: 3.0.0


Offset

<static> Offset(rect, x, y)

Description:

Translates a Rectangle by the given horizontal and vertical amounts, moving its position while preserving its size.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to adjust.
xnumberNoThe distance to move the Rectangle horizontally.
ynumberNoThe distance to move the Rectangle vertically.

Returns: Phaser.Geom.Rectangle - The adjusted Rectangle.

Source: src/geom/rectangle/Offset.js#L7
Since: 3.0.0


OffsetPoint

<static> OffsetPoint(rect, vec)

Description:

Translates the top-left corner of a Rectangle by the coordinates of a translation vector.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to adjust.
vecPhaser.Math.Vector2NoThe Vector2 point whose coordinates should be used as an offset.

Returns: Phaser.Geom.Rectangle - The adjusted Rectangle.

Source: src/geom/rectangle/OffsetPoint.js#L7
Since: 3.0.0


Overlaps

<static> Overlaps(rectA, rectB)

Description:

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".

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to check.
rectBPhaser.Geom.RectangleNoThe second Rectangle to check.

Returns: boolean - true if the two Rectangles overlap, false otherwise.

Source: src/geom/rectangle/Overlaps.js#L7
Since: 3.0.0


Perimeter

<static> Perimeter(rect)

Description:

Calculates the perimeter of a Rectangle.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to use.

Returns: number - The perimeter of the Rectangle, equal to (width * 2) + (height * 2).

Source: src/geom/rectangle/Perimeter.js#L7
Since: 3.0.0


PerimeterPoint

<static> PerimeterPoint(rectangle, angle, [out])

Description:

Returns a point from the perimeter of a Rectangle based on the given angle, measured in degrees from the center of the Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectanglePhaser.Geom.RectangleNoThe Rectangle to get the perimeter point from.
anglenumberNoThe angle of the point, in degrees.
outPhaser.Math.Vector2YesThe Vector2 object to store the position in. If not given, a new Vector2 instance is created.

Returns: Phaser.Math.Vector2 - A Vector2 object holding the coordinates of the point on the Rectangle's perimeter.

Source: src/geom/rectangle/PerimeterPoint.js#L10
Since: 3.0.0


Random

<static> Random(rect, out)

Description:

Returns a random point within a Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to return a point from.
outPhaser.Math.Vector2NoThe object to update with the point's coordinates.

Returns: Phaser.Math.Vector2 - The modified out object, or a new Point if none was provided.

Source: src/geom/rectangle/Random.js#L9
Since: 3.0.0


RandomOutside

<static> RandomOutside(outer, inner, [out])

Description:

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 for a point to be generated. If inner is not fully contained within outer, the function returns the out vector unchanged.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
outerPhaser.Geom.RectangleNoThe outer Rectangle to get the random point within.
innerPhaser.Geom.RectangleNoThe inner Rectangle to exclude from the returned point.
outPhaser.Math.Vector2YesA Vector2 object to store the result in. If not specified, a new Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object containing the random values in its x and y properties.

Source: src/geom/rectangle/RandomOutside.js#L11
Since: 3.10.0


SameDimensions

<static> SameDimensions(rect, toCompare)

Description:

Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe first Rectangle object.
toComparePhaser.Geom.RectangleNoThe second Rectangle object.

Returns: boolean - true if the objects have equivalent values for the width and height properties, otherwise false.

Source: src/geom/rectangle/SameDimensions.js#L7
Since: 3.15.0


Scale

<static> Scale(rect, x, y)

Description:

Scales the width and height of the given Rectangle by the given factors.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle object that will be scaled by the specified amount(s).
xnumberNoThe factor by which to scale the rectangle horizontally.
ynumberNoThe 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.

Returns: Phaser.Geom.Rectangle - The rectangle object with updated width and height properties as calculated from the scaling factor(s).

Source: src/geom/rectangle/Scale.js#L7
Since: 3.0.0


setEmpty

<instance> setEmpty()

Description:

Resets the position, width, and height of the Rectangle to 0.

Returns: Phaser.Geom.Rectangle - This Rectangle object.

Source: src/geom/rectangle/Rectangle.js#L196
Since: 3.0.0


setPosition

<instance> setPosition(x, [y])

Description:

Sets the position of the Rectangle.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe X coordinate of the top left corner of the Rectangle.
ynumberYes"x"The Y coordinate of the top left corner of the Rectangle.

Returns: Phaser.Geom.Rectangle - This Rectangle object.

Source: src/geom/rectangle/Rectangle.js#L209
Since: 3.0.0


setSize

<instance> setSize(width, [height])

Description:

Sets the width and height of the Rectangle.

Parameters:

nametypeoptionaldefaultdescription
widthnumberNoThe width to set the Rectangle to.
heightnumberYes"width"The height to set the Rectangle to.

Returns: Phaser.Geom.Rectangle - This Rectangle object.

Source: src/geom/rectangle/Rectangle.js#L230
Since: 3.0.0


setTo

<instance> setTo(x, y, width, height)

Description:

Sets the position, width, and height of the Rectangle.

Parameters:

nametypeoptionaldescription
xnumberNoThe X coordinate of the top left corner of the Rectangle.
ynumberNoThe Y coordinate of the top left corner of the Rectangle.
widthnumberNoThe width of the Rectangle.
heightnumberNoThe height of the Rectangle.

Returns: Phaser.Geom.Rectangle - This Rectangle object.

Source: src/geom/rectangle/Rectangle.js#L173
Since: 3.0.0


Union

<static> Union(rectA, rectB, [out])

Description:

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.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to use.
rectBPhaser.Geom.RectangleNoThe second Rectangle to use.
outPhaser.Geom.RectangleYesThe Rectangle to store the union in.

Returns: Phaser.Geom.Rectangle - The modified out Rectangle, or a new Rectangle if none was provided.

Source: src/geom/rectangle/Union.js#L9
Since: 3.0.0


Public Members

bottom

bottom: number

Description:

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.

Source: src/geom/rectangle/Rectangle.js#L439
Since: 3.0.0


centerX

centerX: number

Description:

The x coordinate of the center of the Rectangle.

Source: src/geom/rectangle/Rectangle.js#L468
Since: 3.0.0


centerY

centerY: number

Description:

The y coordinate of the center of the Rectangle.

Source: src/geom/rectangle/Rectangle.js#L489
Since: 3.0.0


height

height: number

Description:

The height of the Rectangle, i.e. the distance between its top side (defined by y) and its bottom side.

Source: src/geom/rectangle/Rectangle.js#L88
Since: 3.0.0


left

left: number

Description:

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.

Source: src/geom/rectangle/Rectangle.js#L348
Since: 3.0.0


right: number

Description:

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.

Source: src/geom/rectangle/Rectangle.js#L379
Since: 3.0.0


top

top: number

Description:

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.

Source: src/geom/rectangle/Rectangle.js#L408
Since: 3.0.0


type

type: number

Description:

The geometry constant type of this object: GEOM_CONST.RECTANGLE. Used for fast type comparisons.

Source: src/geom/rectangle/Rectangle.js#L47
Since: 3.19.0


width

width: number

Description:

The width of the Rectangle, i.e. the distance between its left side (defined by x) and its right side.

Source: src/geom/rectangle/Rectangle.js#L78
Since: 3.0.0


x

x: number

Description:

The X coordinate of the top left corner of the Rectangle.

Source: src/geom/rectangle/Rectangle.js#L58
Since: 3.0.0


y

y: number

Description:

The Y coordinate of the top left corner of the Rectangle.

Source: src/geom/rectangle/Rectangle.js#L68
Since: 3.0.0