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

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

centerX :number

The x coordinate of the center of the Rectangle.

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

centerY :number

The y coordinate of the center of the Rectangle.

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

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

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

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

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

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

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

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

Methods


<static> Area(rect)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

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

[description]

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)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

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

[description]

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)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

x number

[description]

y number

[description]

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

[description]

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)

[description]

Parameters:
Name Type Description
rectA Phaser.Geom.Rectangle

[description]

rectB Phaser.Geom.Rectangle

[description]

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

[description]

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)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

toCompare Phaser.Geom.Rectangle

[description]

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

[description]

Type
boolean

<static> FitInside(target, source)

[description]

Parameters:
Name Type Description
target Phaser.Geom.Rectangle

[description]

source Phaser.Geom.Rectangle

[description]

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

[description]

Type
Phaser.Geom.Rectangle

<static> FitOutside(target, source)

[description]

Parameters:
Name Type Description
target Phaser.Geom.Rectangle

[description]

source Phaser.Geom.Rectangle

[description]

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

[description]

Type
Phaser.Geom.Rectangle

<static> Floor(rect)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

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

[description]

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 17)
Returns:

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

Type
Phaser.Geom.Rectangle

<static> GetAspectRatio(rect)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

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

[description]

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

Position is a value between 0 and 1 where 0 = the top-left of the rectangle and 0.5 = the bottom right.

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

[description]

position number

[description]

out Phaser.Geom.Point | object <optional>

[description]

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

[description]

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

[description]

quantity integer

[description]

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

[description]

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

[description]

out Phaser.Geom.Point | object <optional>

[description]

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

[description]

Type
Phaser.Geom.Point | object

<static> Inflate(rect, x, y)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

x number

[description]

y number

[description]

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

[description]

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

[description]

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

[description]

step number

[description]

quantity integer

[description]

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

[description]

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

[description]

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)

[description]

Parameters:
Name Type Description
rectA Phaser.Geom.Rectangle

[description]

rectB Phaser.Geom.Rectangle

[description]

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

[description]

Type
boolean

<static> Perimeter(rect)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

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

[description]

Type
number

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

[description]

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

[description]

angle integer

[description]

out Phaser.Geom.Point <optional>

[description]

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

[description]

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)

[description]

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

[description]

x number

[description]

y number

[description]

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

[description]

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 80)
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 245)
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 266)
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 287)
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 308)
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 96)
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 integer

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 118)
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 137)
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 232)
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 177)
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 190)
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 211)
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 154)
Returns:

This Rectangle object.

Type
Phaser.Geom.Rectangle