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.
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. |
The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
The 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.
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.
The x coordinate of the center of the Rectangle.
The y coordinate of the center of the Rectangle.
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.
Half of the height of the Rectangle.
Half of the width of the Rectangle.
The height of the Rectangle. This value should never be set to a negative.
The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
The perimeter size of the Rectangle. This is the sum of all 4 sides.
A random value between the left and right values (inclusive) of the Rectangle.
A random value between the top and bottom values (inclusive) of the Rectangle.
The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties, however it does affect the width property.
The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
However it does affect the height property, whereas changing the y value does not affect the height property.
The location of the Rectangles top left corner as a Point object.
The location of the Rectangles top right corner as a Point object. The location of the Rectangles top left corner as a Point object.
The const type of this object.
The volume of the Rectangle derived from width * height.
The width of the Rectangle. This value should never be set to a negative.
The x coordinate of the top-left corner of the Rectangle.
The y coordinate of the top-left corner of the Rectangle.
Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
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. |
Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
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. |
A value of true if the Rectangle object contains the specified point; otherwise false.
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.
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. |
A value of true if the Rectangle object contains the specified point; otherwise false.
Determines whether the specified coordinates are contained within the region defined by the given raw values.
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. |
A value of true if the Rectangle object contains the specified point; otherwise false.
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.
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The first Rectangle object. |
b | Phaser.Rectangle | The second Rectangle object. |
A value of true if the Rectangle object contains the specified point; otherwise false.
Determines whether the two Rectangles are equal.
This method compares the x, y, width and height properties of each Rectangle.
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The first Rectangle object. |
b | Phaser.Rectangle | The second Rectangle object. |
A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
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.
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. |
This Rectangle object.
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.
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. |
The Rectangle object.
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.
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. |
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.
Determines whether the two Rectangles intersect with each other.
This method checks the x, y, width, and height properties of the Rectangles.
Name | Type | Description |
---|---|---|
a | Phaser.Rectangle | The first Rectangle object. |
b | Phaser.Rectangle | The second Rectangle object. |
A value of true if the specified object intersects with this Rectangle object; otherwise false.
Determines whether the object specified intersects (overlaps) with the given values.
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 |
A value of true if the specified object intersects with the Rectangle; otherwise false.
Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.
Name | Type | Description |
---|---|---|
a | Rectangle-like | The first Rectangle object. |
b | Rectangle-like | The second Rectangle object. |
True if the object have equivalent values for the width and height properties.
The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
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. |
The size of the Rectangle object
Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
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. |
A Rectangle object that is the union of the two Rectangles.
Calculates the Axis Aligned Bounding Box (or aabb) from an array of points.
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. |
The new Rectangle object.
Runs Math.ceil() on both the x and y values of this Rectangle.
Runs Math.ceil() on the x, y, width and height values of this Rectangle.
Centers this Rectangle so that the center coordinates match the given x and y values.
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. |
This Rectangle object
Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
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. |
Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
Name | Type | Description |
---|---|---|
x | number | The x coordinate of the point to test. |
y | number | The y coordinate of the point to test. |
A value of true if the Rectangle object contains the specified point; otherwise false.
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.
Name | Type | Description |
---|---|---|
b | Phaser.Rectangle | The second Rectangle object. |
A value of true if the Rectangle object contains the specified point; otherwise false.
Copies the x, y, width and height properties from any given object to this Rectangle.
Name | Type | Description |
---|---|---|
source | any | The object to copy from. |
This Rectangle object.
Copies the x, y, width and height properties from this Rectangle to any given object.
Name | Type | Description |
---|---|---|
source | any | The object to copy to. |
This object.
Determines whether the two Rectangles are equal.
This method compares the x, y, width and height properties of each Rectangle.
Name | Type | Description |
---|---|---|
b | Phaser.Rectangle | The second Rectangle object. |
A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
Runs Math.floor() on both the x and y values of this Rectangle.
Runs Math.floor() on the x, y, width and height values of this Rectangle.
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.
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. |
An object containing the point in its x
and y
properties.
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.
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. |
This Rectangle object.
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.
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. |
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.
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.
Name | Type | Description |
---|---|---|
b | Phaser.Rectangle | The second Rectangle object. |
A value of true if the specified object intersects with this Rectangle object; otherwise false.
Determines whether the coordinates given intersects (overlaps) with this Rectangle.
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 |
A value of true if the specified object intersects with the Rectangle; otherwise false.
Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
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. |
This Rectangle object.
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.
Name | Type | Description |
---|---|---|
point | Phaser.Point | A Point object to use to offset this Rectangle object. |
This Rectangle object.
Returns a uniformly distributed random point from anywhere within this Rectangle.
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. |
An object containing the random point in its x
and y
properties.
Resize the Rectangle by providing a new width and height.
The x and y positions remain unchanged.
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. |
This Rectangle object
Scales the width and height of this Rectangle by the given amounts.
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. |
This Rectangle object
Sets the members of Rectangle to the specified values.
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. |
This Rectangle object
The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
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. |
The size of the Rectangle object.
Returns a string representation of this object.
A string representation of the instance.
Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
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. |
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