Class: Rectangle

Phaser.Geom. Rectangle

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])

Parameters:
Name Type Argument Default Description
x number <optional>
0

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

y number <optional>
0

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

width number <optional>
0

The width of the Rectangle.

height number <optional>
0

The height of the Rectangle.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 15)

Members


bottom :number

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.

Type:
  • number
Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 432)

centerX :number

The x coordinate of the center of the Rectangle.

Type:
  • number
Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 461)

centerY :number

The y coordinate of the center of the Rectangle.

Type:
  • number
Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 482)

height :number

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

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/geom/rectangle/Rectangle.js (Line 81)

left :number

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.

Type:
  • number
Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 341)

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.

Type:
  • number
Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 372)

top :number

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.

Type:
  • number
Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 401)

<readonly> type :number

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

Type:
  • number
Since: 3.19.0
Source: src/geom/rectangle/Rectangle.js (Line 40)

width :number

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

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/geom/rectangle/Rectangle.js (Line 71)

x :number

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

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/geom/rectangle/Rectangle.js (Line 51)

y :number

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

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/geom/rectangle/Rectangle.js (Line 61)

Methods


<static> Area(rect)

Calculates the area of the given Rectangle object.

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The rectangle to calculate the area of.

Since: 3.0.0
Source: src/geom/rectangle/Area.js (Line 7)
Returns:

The area of the Rectangle object.

Type
number

<static> Ceil(rect)

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

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The Rectangle to adjust.

Since: 3.0.0
Source: src/geom/rectangle/Ceil.js (Line 7)
Returns:

The adjusted Rectangle.

Type
Phaser.Geom.Rectangle

<static> CeilAll(rect)

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

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The Rectangle to modify.

Since: 3.0.0
Source: src/geom/rectangle/CeilAll.js (Line 7)
Returns:

The modified Rectangle.

Type
Phaser.Geom.Rectangle

<static> CenterOn(rect, x, y)

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

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/CenterOn.js (Line 9)
Returns:

The centered rectangle.

Type
Phaser.Geom.Rectangle

<static> Clone(source)

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

Parameters:
Name Type Description
source Phaser.Geom.Rectangle

The Rectangle to clone.

Since: 3.0.0
Source: src/geom/rectangle/Clone.js (Line 9)
Returns:

The newly created Rectangle, which is separate from the given one.

Type
Phaser.Geom.Rectangle

<static> Contains(rect, x, y)

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

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/Contains.js (Line 7)
Returns:

true if the point is within the Rectangle's bounds, otherwise false.

Type
boolean

<static> ContainsPoint(rect, point)

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

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/ContainsPoint.js (Line 9)
Returns:

A value of true if the Rectangle object contains the specified point, otherwise false.

Type
boolean

<static> ContainsRect(rectA, rectB)

Tests if one rectangle fully contains another.

Parameters:
Name Type Description
rectA Phaser.Geom.Rectangle

The first rectangle.

rectB Phaser.Geom.Rectangle

The second rectangle.

Since: 3.0.0
Source: src/geom/rectangle/ContainsRect.js (Line 7)
Returns:

True only if rectA fully contains rectB.

Type
boolean

<static> CopyFrom(source, dest)

Copy the values of one Rectangle to a destination Rectangle.

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/CopyFrom.js (Line 7)
Returns:

The destination Rectangle.

Type
Phaser.Geom.Rectangle

<static> Decompose(rect [, out])

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.

Parameters:
Name Type Argument Description
rect Phaser.Geom.Rectangle

The Rectangle object to be decomposed.

out array <optional>

If provided, each point will be added to this array.

Since: 3.0.0
Source: src/geom/rectangle/Decompose.js (Line 7)
Returns:

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

Type
array

<static> Equals(rect, toCompare)

Compares the x, y, width and height properties of two rectangles.

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

Rectangle A

toCompare Phaser.Geom.Rectangle

Rectangle B

Since: 3.0.0
Source: src/geom/rectangle/Equals.js (Line 7)
Returns:

true if the rectangles' properties are an exact match, otherwise false.

Type
boolean

<static> FitInside(target, source)

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.

Parameters:
Name Type Description
target Phaser.Geom.Rectangle

The target rectangle to adjust.

source Phaser.Geom.Rectangle

The source rectangle to envelop the target in.

Since: 3.0.0
Source: src/geom/rectangle/FitInside.js (Line 9)
Returns:

The modified target rectangle instance.

Type
Phaser.Geom.Rectangle

<static> FitOutside(target, source)

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.

Parameters:
Name Type Description
target Phaser.Geom.Rectangle

The target rectangle to adjust.

source Phaser.Geom.Rectangle

The source rectangle to envelope the target in.

Since: 3.0.0
Source: src/geom/rectangle/FitOutside.js (Line 9)
Returns:

The modified target rectangle instance.

Type
Phaser.Geom.Rectangle

<static> Floor(rect)

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

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The rectangle to floor the top left X and Y coordinates of

Since: 3.0.0
Source: src/geom/rectangle/Floor.js (Line 7)
Returns:

The rectangle that was passed to this function with its coordinates floored.

Type
Phaser.Geom.Rectangle

<static> FloorAll(rect)

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

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The Rectangle to adjust.

Since: 3.0.0
Source: src/geom/rectangle/FloorAll.js (Line 7)
Returns:

The adjusted Rectangle.

Type
Phaser.Geom.Rectangle

<static> FromPoints(points [, out])

Constructs new Rectangle or repositions and resizes an existing Rectangle so that all of the given points are on or within its bounds.

Parameters:
Name Type Argument Description
points array

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.

out Phaser.Geom.Rectangle <optional>

Optional Rectangle to adjust.

Since: 3.0.0
Source: src/geom/rectangle/FromPoints.js (Line 18)
Returns:

The adjusted out Rectangle, or a new Rectangle if none was provided.

Type
Phaser.Geom.Rectangle

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

Create the smallest Rectangle containing two coordinate pairs.

Parameters:
Name Type Argument 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.

Since: 3.23.0
Source: src/geom/rectangle/FromXY.js (Line 9)
Returns:

The adjusted out Rectangle, or a new Rectangle if none was provided.

Type
Phaser.Geom.Rectangle

<static> GetAspectRatio(rect)

Calculates the width/height ratio of a rectangle.

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The rectangle.

Since: 3.0.0
Source: src/geom/rectangle/GetAspectRatio.js (Line 7)
Returns:

The width/height ratio of the rectangle.

Type
number

<static> GetCenter(rect [, out])

Returns the center of a Rectangle as a Point.

Parameters:
Name Type Argument Description
rect Phaser.Geom.Rectangle

The Rectangle to get the center of.

out Phaser.Geom.Point | object <optional>

Optional point-like object to update with the center coordinates.

Since: 3.0.0
Source: src/geom/rectangle/GetCenter.js (Line 9)
Returns:

The modified out object, or a new Point if none was provided.

Type
Phaser.Geom.Point | object

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

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.

Parameters:
Name Type Argument 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 Phaser.Geom.Point | object <optional>

An object to update with the x and y coordinates of the point.

Since: 3.0.0
Source: src/geom/rectangle/GetPoint.js (Line 10)
Returns:

The updated output object, or a new Point if no output object was given.

Type
Phaser.Geom.Point

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

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

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/geom/rectangle/GetPoints.js (Line 13)
Returns:

An array of Points from the perimeter of the rectangle.

Type
array | Array.<Phaser.Geom.Point>

<static> GetSize(rect [, out])

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.

Parameters:
Name Type Argument Description
rect Phaser.Geom.Rectangle

The Rectangle to get the size from.

out Phaser.Geom.Point | object <optional>

The Point object to store the size in. If not given, a new Point instance is created.

Since: 3.0.0
Source: src/geom/rectangle/GetSize.js (Line 10)
Returns:

A Point object where x holds the width and y holds the height of the Rectangle.

Type
Phaser.Geom.Point | object

<static> Inflate(rect, x, y)

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.

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/Inflate.js (Line 10)
Returns:

The inflated Rectangle.

Type
Phaser.Geom.Rectangle

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

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.

Parameters:
Name Type Argument 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.

Since: 3.11.0
Source: src/geom/rectangle/Intersection.js (Line 10)
Returns:

The intersection result. If the width and height are zero, no intersection occurred.

Type
Phaser.Geom.Rectangle

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

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.

Parameters:
Name Type Argument 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 null if you wish to use the quantity parameter instead.

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.

Since: 3.0.0
Source: src/geom/rectangle/MarchingAnts.js (Line 11)
Returns:

An array containing the perimeter points from the Rectangle.

Type
array | Array.<Phaser.Geom.Point>

<static> MergePoints(target, points)

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.

Parameters:
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 x and y properties) which should be merged with the Rectangle.

Since: 3.0.0
Source: src/geom/rectangle/MergePoints.js (Line 7)
Returns:

The modified Rectangle.

Type
Phaser.Geom.Rectangle

<static> MergeRect(target, source)

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

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/MergeRect.js (Line 10)
Returns:

Modified target rectangle that contains source rectangle.

Type
Phaser.Geom.Rectangle

<static> MergeXY(target, x, y)

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

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/MergeXY.js (Line 7)
Returns:

The modified target Rectangle.

Type
Phaser.Geom.Rectangle

<static> Offset(rect, x, y)

Nudges (translates) the top left corner of a Rectangle by a given offset.

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/Offset.js (Line 7)
Returns:

The adjusted Rectangle.

Type
Phaser.Geom.Rectangle

<static> OffsetPoint(rect, point)

Nudges (translates) the top-left corner of a Rectangle by the coordinates of a point (translation vector).

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/OffsetPoint.js (Line 7)
Returns:

The adjusted Rectangle.

Type
Phaser.Geom.Rectangle

<static> Overlaps(rectA, rectB)

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:
Name Type Description
rectA Phaser.Geom.Rectangle

The first Rectangle to check.

rectB Phaser.Geom.Rectangle

The second Rectangle to check.

Since: 3.0.0
Source: src/geom/rectangle/Overlaps.js (Line 7)
Returns:

true if the two Rectangles overlap, false otherwise.

Type
boolean

<static> Perimeter(rect)

Calculates the perimeter of a Rectangle.

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The Rectangle to use.

Since: 3.0.0
Source: src/geom/rectangle/Perimeter.js (Line 7)
Returns:

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

Type
number

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

Returns a Point from the perimeter of a Rectangle based on the given angle.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/geom/rectangle/PerimeterPoint.js (Line 10)
Returns:

A Point object holding the coordinates of the Rectangle perimeter.

Type
Phaser.Geom.Point

<static> Random(rect, out)

Returns a random point within a Rectangle.

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/Random.js (Line 9)
Returns:

The modified out object, or a new Point if none was provided.

Type
Phaser.Geom.Point

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

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.

Parameters:
Name Type Argument 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.

Since: 3.10.0
Source: src/geom/rectangle/RandomOutside.js (Line 11)
Returns:

A Point object containing the random values in its x and y properties.

Type
Phaser.Geom.Point

<static> SameDimensions(rect, toCompare)

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

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The first Rectangle object.

toCompare Phaser.Geom.Rectangle

The second Rectangle object.

Since: 3.15.0
Source: src/geom/rectangle/SameDimensions.js (Line 7)
Returns:

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

Type
boolean

<static> Scale(rect, x, y)

Scales the width and height of this Rectangle by the given amounts.

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

The Rectangle object that will be scaled by the specified amount(s).

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 x in both directions.

Since: 3.0.0
Source: src/geom/rectangle/Scale.js (Line 9)
Returns:

The rectangle object with updated width and height properties as calculated from the scaling factor(s).

Type
Phaser.Geom.Rectangle

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

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.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/geom/rectangle/Union.js (Line 9)
Returns:

The modified out Rectangle, or a new Rectangle if none was provided.

Type
Phaser.Geom.Rectangle

contains(x, y)

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

Parameters:
Name Type Description
x number

The X coordinate of the point to check.

y number

The Y coordinate of the point to check.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 92)
Returns:

true if the point is within the Rectangle's bounds, otherwise false.

Type
boolean

getLineA( [line])

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

Parameters:
Name Type Argument Description
line Phaser.Geom.Line <optional>

A Line object to set the results in. If undefined a new Line will be created.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 257)
Returns:

A Line object that corresponds to the top of this Rectangle.

Type
Phaser.Geom.Line

getLineB( [line])

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

Parameters:
Name Type Argument Description
line Phaser.Geom.Line <optional>

A Line object to set the results in. If undefined a new Line will be created.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 278)
Returns:

A Line object that corresponds to the right of this Rectangle.

Type
Phaser.Geom.Line

getLineC( [line])

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

Parameters:
Name Type Argument Description
line Phaser.Geom.Line <optional>

A Line object to set the results in. If undefined a new Line will be created.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 299)
Returns:

A Line object that corresponds to the bottom of this Rectangle.

Type
Phaser.Geom.Line

getLineD( [line])

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

Parameters:
Name Type Argument Description
line Phaser.Geom.Line <optional>

A Line object to set the results in. If undefined a new Line will be created.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 320)
Returns:

A Line object that corresponds to the left of this Rectangle.

Type
Phaser.Geom.Line

getPoint(position [, output])

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.

Parameters:
Name Type Argument Description
position number

The normalized distance into the Rectangle's perimeter to return.

output Phaser.Geom.Point | object <optional>

An object to update with the x and y coordinates of the point.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 108)
Returns:

The updated output object, or a new Point if no output object was given.

Type
Phaser.Geom.Point | object

getPoints(quantity [, stepRate] [, output])

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

Parameters:
Name Type Argument Description
quantity number

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.

stepRate number <optional>

If quantity is 0, determines the normalized distance between each returned point.

output array | Array.<Phaser.Geom.Point> <optional>

An array to which to append the points.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 130)
Returns:

The modified output array, or a new array if none was provided.

Type
array | Array.<Phaser.Geom.Point>

getRandomPoint( [point])

Returns a random point within the Rectangle's bounds.

Parameters:
Name Type Argument Description
point Phaser.Geom.Point <optional>

The object in which to store the x and y coordinates of the point.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 149)
Returns:

The updated point, or a new Point if none was provided.

Type
Phaser.Geom.Point

isEmpty()

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

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 244)
Returns:

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

Type
boolean

setEmpty()

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

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 189)
Returns:

This Rectangle object.

Type
Phaser.Geom.Rectangle

setPosition(x [, y])

Sets the position of the Rectangle.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 202)
Returns:

This Rectangle object.

Type
Phaser.Geom.Rectangle

setSize(width [, height])

Sets the width and height of the Rectangle.

Parameters:
Name Type Argument Default Description
width number

The width to set the Rectangle to.

height number <optional>
width

The height to set the Rectangle to.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 223)
Returns:

This Rectangle object.

Type
Phaser.Geom.Rectangle

setTo(x, y, width, height)

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

Parameters:
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.

Since: 3.0.0
Source: src/geom/rectangle/Rectangle.js (Line 166)
Returns:

This Rectangle object.

Type
Phaser.Geom.Rectangle