Class: Phaser.Rectangle
Constructor
new Rectangle(x, y, width, height)
Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters.
If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
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. Should always be either zero or a positive value. |
height | number | The height of the Rectangle. Should always be either zero or a positive value. |
- Source code: geom/Rectangle.js (Line 18)
Public Properties
- Source code: geom/Rectangle.js (Line 478)
- Source code: geom/Rectangle.js (Line 504)
- Source code: geom/Rectangle.js (Line 522)
- Source code: geom/Rectangle.js (Line 611)
- Source code: geom/Rectangle.js (Line 628)
- Source code: geom/Rectangle.js (Line 736)
- Source code: geom/Rectangle.js (Line 465)
- Source code: geom/Rectangle.js (Line 452)
- Source code: geom/Rectangle.js (Line 43)
- Source code: geom/Rectangle.js (Line 540)
- Source code: geom/Rectangle.js (Line 597)
- Source code: geom/Rectangle.js (Line 645)
- Source code: geom/Rectangle.js (Line 661)
- Source code: geom/Rectangle.js (Line 562)
- Source code: geom/Rectangle.js (Line 677)
- Source code: geom/Rectangle.js (Line 700)
- Source code: geom/Rectangle.js (Line 718)
- Source code: geom/Rectangle.js (Line 49)
- Source code: geom/Rectangle.js (Line 583)
- Source code: geom/Rectangle.js (Line 38)
- Source code: geom/Rectangle.js (Line 28)
- Source code: geom/Rectangle.js (Line 33)
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.
bottomLeft : Phaser.Point
The location of the Rectangles bottom left corner as a Point object. Gets or sets the location of the Rectangles bottom left corner as a Point object.
bottomRight : Phaser.Point
The location of the Rectangles bottom right corner as a Point object. Gets or sets the location of the Rectangles bottom right corner as a Point object.
centerX : number
The x coordinate of the center of the Rectangle.
centerY : number
The y coordinate of the center of the Rectangle.
empty : boolean
Determines whether or not this Rectangle object is empty. A Rectangle object is empty if its width or height is less than or equal to 0.
If set to true then all of the Rectangle properties are set to 0. Gets or sets the Rectangles empty state.
[readonly] halfHeight : number
Half of the height of the Rectangle.
[readonly] halfWidth : number
Half of the width of the Rectangle.
height : number
The height of the Rectangle. This value should never be set to a negative.
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.
[readonly] perimeter : number
The perimeter size of the Rectangle. This is the sum of all 4 sides.
randomX : number
A random value between the left and right values (inclusive) of the Rectangle.
randomY : number
A random value between the top and bottom values (inclusive) of the Rectangle.
right : number
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.
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.
topLeft : Phaser.Point
The location of the Rectangles top left corner as a Point object.
topRight : Phaser.Point
The location of the Rectangles top right corner as a Point object. The location of the Rectangles top left corner as a Point object.
[readonly] type : number
The const type of this object.
[readonly] volume : number
The volume of the Rectangle derived from width * height.
width : number
The width of the Rectangle. This value should never be set to a negative.
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.
Public Methods
- Source code: geom/Rectangle.js (Line 815)
- Source code: geom/Rectangle.js (Line 837)
- Source code: geom/Rectangle.js (Line 873)
- Source code: geom/Rectangle.js (Line 856)
- Source code: geom/Rectangle.js (Line 886)
- Source code: geom/Rectangle.js (Line 906)
- Source code: geom/Rectangle.js (Line 761)
- Source code: geom/Rectangle.js (Line 780)
- Source code: geom/Rectangle.js (Line 933)
- Source code: geom/Rectangle.js (Line 960)
- Source code: geom/Rectangle.js (Line 979)
- Source code: geom/Rectangle.js (Line 920)
- Source code: geom/Rectangle.js (Line 793)
- Source code: geom/Rectangle.js (Line 997)
- Source code: geom/Rectangle.js (Line 1016)
- Source code: geom/Rectangle.js (Line 163)
- Source code: geom/Rectangle.js (Line 174)
- Source code: geom/Rectangle.js (Line 122)
- Source code: geom/Rectangle.js (Line 259)
- Source code: geom/Rectangle.js (Line 271)
- Source code: geom/Rectangle.js (Line 284)
- Source code: geom/Rectangle.js (Line 187)
- Source code: geom/Rectangle.js (Line 199)
- Source code: geom/Rectangle.js (Line 297)
- Source code: geom/Rectangle.js (Line 139)
- Source code: geom/Rectangle.js (Line 150)
- Source code: geom/Rectangle.js (Line 386)
- Source code: geom/Rectangle.js (Line 216)
- Source code: geom/Rectangle.js (Line 310)
- Source code: geom/Rectangle.js (Line 323)
- Source code: geom/Rectangle.js (Line 337)
- Source code: geom/Rectangle.js (Line 55)
- Source code: geom/Rectangle.js (Line 71)
- Source code: geom/Rectangle.js (Line 367)
- Source code: geom/Rectangle.js (Line 241)
- Source code: geom/Rectangle.js (Line 103)
- Source code: geom/Rectangle.js (Line 83)
- Source code: geom/Rectangle.js (Line 229)
- Source code: geom/Rectangle.js (Line 439)
- Source code: geom/Rectangle.js (Line 354)
<static> clone(a, output) → {Phaser.Rectangle}
Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
a | Phaser.Rectangle | The Rectangle object. | |
output | Phaser.Rectangle | <optional> | Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. |
Returns
<static> contains(a, x, y) → {boolean}
Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
Parameters
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The Rectangle object. |
x | number | The x coordinate of the point to test. |
y | number | The y coordinate of the point to test. |
Returns
A value of true if the Rectangle object contains the specified point; otherwise false.
<static> containsPoint(a, point) → {boolean}
Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter.
Parameters
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The Rectangle object. |
point | Phaser.Point | The point object being checked. Can be Point or any object with .x and .y values. |
Returns
A value of true if the Rectangle object contains the specified point; otherwise false.
<static> containsRaw(rx, ry, rw, rh, x, y) → {boolean}
Determines whether the specified coordinates are contained within the region defined by the given raw values.
Parameters
Name | Type | Description |
---|---|---|
rx | number | The x coordinate of the top left of the area. |
ry | number | The y coordinate of the top left of the area. |
rw | number | The width of the area. |
rh | number | The height of the area. |
x | number | The x coordinate of the point to test. |
y | number | The y coordinate of the point to test. |
Returns
A value of true if the Rectangle object contains the specified point; otherwise false.
<static> containsRect(a, b) → {boolean}
Determines whether the first Rectangle object is fully contained within the second Rectangle object.
A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
Parameters
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The first Rectangle object. |
b | Phaser.Rectangle | The second Rectangle object. |
Returns
A value of true if the Rectangle object contains the specified point; otherwise false.
<static> equals(a, b) → {boolean}
Determines whether the two Rectangles are equal.
This method compares the x, y, width and height properties of each Rectangle.
Parameters
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The first Rectangle object. |
b | Phaser.Rectangle | The second Rectangle object. |
Returns
A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
<static> inflate(a, dx, dy) → {Phaser.Rectangle}
Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
Parameters
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The Rectangle object. |
dx | number | The amount to be added to the left side of the Rectangle. |
dy | number | The amount to be added to the bottom side of the Rectangle. |
Returns
This Rectangle object.
<static> inflatePoint(a, point) → {Phaser.Rectangle}
Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.
Parameters
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The Rectangle object. |
point | Phaser.Point | The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object. |
Returns
The Rectangle object.
<static> intersection(a, b, output) → {Phaser.Rectangle}
If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
a | Phaser.Rectangle | The first Rectangle object. | |
b | Phaser.Rectangle | The second Rectangle object. | |
output | Phaser.Rectangle | <optional> | Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. |
Returns
A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
<static> intersects(a, b) → {boolean}
Determines whether the two Rectangles intersect with each other.
This method checks the x, y, width, and height properties of the Rectangles.
Parameters
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The first Rectangle object. |
b | Phaser.Rectangle | The second Rectangle object. |
Returns
A value of true if the specified object intersects with this Rectangle object; otherwise false.
<static> intersectsRaw(left, right, top, bottom, tolerance) → {boolean}
Determines whether the object specified intersects (overlaps) with the given values.
Parameters
Name | Type | Description |
---|---|---|
left | number | The x coordinate of the left of the area. |
right | number | The right coordinate of the area. |
top | number | The y coordinate of the area. |
bottom | number | The bottom coordinate of the area. |
tolerance | number | A tolerance value to allow for an intersection test with padding, default to 0 |
Returns
A value of true if the specified object intersects with the Rectangle; otherwise false.
<static> sameDimensions(a, b) → {boolean}
Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.
Parameters
Name | Type | Description |
---|---|---|
a | Rectangle-like | The first Rectangle object. |
b | Rectangle-like | The second Rectangle object. |
Returns
True if the object have equivalent values for the width and height properties.
<static> size(a, output) → {Phaser.Point}
The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
a | Phaser.Rectangle | The Rectangle object. | |
output | Phaser.Point | <optional> | Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. |
Returns
The size of the Rectangle object
<static> union(a, b, output) → {Phaser.Rectangle}
Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
a | Phaser.Rectangle | The first Rectangle object. | |
b | Phaser.Rectangle | The second Rectangle object. | |
output | Phaser.Rectangle | <optional> | Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. |
Returns
A Rectangle object that is the union of the two Rectangles.
aabb(points, out) → {Phaser.Rectangle}
Calculates the Axis Aligned Bounding Box (or aabb) from an array of points.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
points | Array.<Phaser.Point> | The array of one or more points. | |
out | Phaser.Rectangle | <optional> | Optional Rectangle to store the value in, if not supplied a new Rectangle object will be created. |
Returns
The new Rectangle object.
ceil()
Runs Math.ceil() on both the x and y values of this Rectangle.
ceilAll()
Runs Math.ceil() on the x, y, width and height values of this Rectangle.
centerOn(x, y) → {Phaser.Rectangle}
Centers this Rectangle so that the center coordinates match the given x and y values.
Parameters
Name | Type | Description |
---|---|---|
x | number | The x coordinate to place the center of the Rectangle at. |
y | number | The y coordinate to place the center of the Rectangle at. |
Returns
This Rectangle object
clone(output) → {Phaser.Rectangle}
Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
output | Phaser.Rectangle | <optional> | Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. |
Returns
contains(x, y) → {boolean}
Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
Parameters
Name | Type | Description |
---|---|---|
x | number | The x coordinate of the point to test. |
y | number | The y coordinate of the point to test. |
Returns
A value of true if the Rectangle object contains the specified point; otherwise false.
containsRect(b) → {boolean}
Determines whether the first Rectangle object is fully contained within the second Rectangle object.
A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
Parameters
Name | Type | Description |
---|---|---|
b | Phaser.Rectangle | The second Rectangle object. |
Returns
A value of true if the Rectangle object contains the specified point; otherwise false.
copyFrom(source) → {Phaser.Rectangle}
Copies the x, y, width and height properties from any given object to this Rectangle.
Parameters
Name | Type | Description |
---|---|---|
source | any | The object to copy from. |
Returns
This Rectangle object.
copyTo(source) → {object}
Copies the x, y, width and height properties from this Rectangle to any given object.
Parameters
Name | Type | Description |
---|---|---|
source | any | The object to copy to. |
Returns
This object.
equals(b) → {boolean}
Determines whether the two Rectangles are equal.
This method compares the x, y, width and height properties of each Rectangle.
Parameters
Name | Type | Description |
---|---|---|
b | Phaser.Rectangle | The second Rectangle object. |
Returns
A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
floor()
Runs Math.floor() on both the x and y values of this Rectangle.
floorAll()
Runs Math.floor() on the x, y, width and height values of this Rectangle.
getPoint(position, out) → {Phaser.Point}
Returns a point based on the given position constant, which can be one of:
Phaser.TOP_LEFT
, Phaser.TOP_CENTER
, Phaser.TOP_RIGHT
, Phaser.LEFT_CENTER
,Phaser.CENTER
, Phaser.RIGHT_CENTER
, Phaser.BOTTOM_LEFT
, Phaser.BOTTOM_CENTER
and Phaser.BOTTOM_RIGHT
.
This method returns the same values as calling Rectangle.bottomLeft, etc, but those
calls always create a new Point object, where-as this one allows you to use your own.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
position | integer | <optional> | One of the Phaser position constants, such as |
out | Phaser.Point | <optional> | A Phaser.Point that the values will be set in. |
Returns
An object containing the point in its x
and y
properties.
inflate(dx, dy) → {Phaser.Rectangle}
Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
Parameters
Name | Type | Description |
---|---|---|
dx | number | The amount to be added to the left side of the Rectangle. |
dy | number | The amount to be added to the bottom side of the Rectangle. |
Returns
This Rectangle object.
intersection(b, out) → {Phaser.Rectangle}
If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
Parameters
Name | Type | Description |
---|---|---|
b | Phaser.Rectangle | The second Rectangle object. |
out | Phaser.Rectangle | Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. |
Returns
A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
intersects(b) → {boolean}
Determines whether this Rectangle and another given Rectangle intersect with each other.
This method checks the x, y, width, and height properties of the two Rectangles.
Parameters
Name | Type | Description |
---|---|---|
b | Phaser.Rectangle | The second Rectangle object. |
Returns
A value of true if the specified object intersects with this Rectangle object; otherwise false.
intersectsRaw(left, right, top, bottom, tolerance) → {boolean}
Determines whether the coordinates given intersects (overlaps) with this Rectangle.
Parameters
Name | Type | Description |
---|---|---|
left | number | The x coordinate of the left of the area. |
right | number | The right coordinate of the area. |
top | number | The y coordinate of the area. |
bottom | number | The bottom coordinate of the area. |
tolerance | number | A tolerance value to allow for an intersection test with padding, default to 0 |
Returns
A value of true if the specified object intersects with the Rectangle; otherwise false.
offset(dx, dy) → {Phaser.Rectangle}
Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
Parameters
Name | Type | Description |
---|---|---|
dx | number | Moves the x value of the Rectangle object by this amount. |
dy | number | Moves the y value of the Rectangle object by this amount. |
Returns
This Rectangle object.
offsetPoint(point) → {Phaser.Rectangle}
Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
Parameters
Name | Type | Description |
---|---|---|
point | Phaser.Point | A Point object to use to offset this Rectangle object. |
Returns
This Rectangle object.
random(out) → {Phaser.Point}
Returns a uniformly distributed random point from anywhere within this Rectangle.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
out | Phaser.Point | object | <optional> | A Phaser.Point, or any object with public x/y properties, that the values will be set in. |
Returns
An object containing the random point in its x
and y
properties.
resize(width, height) → {Phaser.Rectangle}
Resize the Rectangle by providing a new width and height.
The x and y positions remain unchanged.
Parameters
Name | Type | Description |
---|---|---|
width | number | The width of the Rectangle. Should always be either zero or a positive value. |
height | number | The height of the Rectangle. Should always be either zero or a positive value. |
Returns
This Rectangle object
scale(x, y) → {Phaser.Rectangle}
Scales the width and height of this Rectangle by the given amounts.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
x | number | The amount to scale the width of the Rectangle by. A value of 0.5 would reduce by half, a value of 2 would double the width, etc. | |
y | number | <optional> | The amount to scale the height of the Rectangle by. A value of 0.5 would reduce by half, a value of 2 would double the height, etc. |
Returns
This Rectangle object
setTo(x, y, width, height) → {Phaser.Rectangle}
Sets the members of Rectangle to the specified values.
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. Should always be either zero or a positive value. |
height | number | The height of the Rectangle. Should always be either zero or a positive value. |
Returns
This Rectangle object
size(output) → {Phaser.Point}
The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
output | Phaser.Point | <optional> | Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. |
Returns
The size of the Rectangle object.
toString() → {string}
Returns a string representation of this object.
Returns
A string representation of the instance.
union(b, out) → {Phaser.Rectangle}
Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
b | Phaser.Rectangle | The second Rectangle object. | |
out | Phaser.Rectangle | <optional> | Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. |
Returns
A Rectangle object that is the union of the two Rectangles.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Rectangle.html