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:
- src/geom/Rectangle.js line 18
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
- Source:
- src/geom/Rectangle.js line 478
-
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.
Type:
- Source:
- src/geom/Rectangle.js line 504
-
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.
Type:
- Source:
- src/geom/Rectangle.js line 522
-
centerX : number
-
The x coordinate of the center of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 611
-
centerY : number
-
The y coordinate of the center of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 628
-
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.
Type:
- boolean
- Source:
- src/geom/Rectangle.js line 736
-
<readonly> halfHeight : number
-
Half of the height of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 465
-
<readonly> halfWidth : number
-
Half of the width of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 452
-
height : number
-
The height of the Rectangle. This value should never be set to a negative.
Type:
- number
- Source:
- src/geom/Rectangle.js line 43
-
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
- Source:
- src/geom/Rectangle.js line 540
-
<readonly> perimeter : number
-
The perimeter size of the Rectangle. This is the sum of all 4 sides.
Type:
- number
- Source:
- src/geom/Rectangle.js line 597
-
randomX : number
-
A random value between the left and right values (inclusive) of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 645
-
randomY : number
-
A random value between the top and bottom values (inclusive) of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 661
-
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.
Type:
- number
- Source:
- src/geom/Rectangle.js line 562
-
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
- Source:
- src/geom/Rectangle.js line 677
-
topLeft : Phaser.Point
-
The location of the Rectangles top left corner as a Point object.
Type:
- Source:
- src/geom/Rectangle.js line 700
-
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.
Type:
- Source:
- src/geom/Rectangle.js line 718
-
<readonly> type : number
-
The const type of this object.
Type:
- number
- Source:
- src/geom/Rectangle.js line 49
-
<readonly> volume : number
-
The volume of the Rectangle derived from width * height.
Type:
- number
- Source:
- src/geom/Rectangle.js line 583
-
width : number
-
The width of the Rectangle. This value should never be set to a negative.
Type:
- number
- Source:
- src/geom/Rectangle.js line 38
-
x : number
-
The x coordinate of the top-left corner of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 28
-
y : number
-
The y coordinate of the top-left corner of the Rectangle.
Type:
- number
- Source:
- src/geom/Rectangle.js line 33
Methods
-
<static> clone(a [, output])
-
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 aPhaser.Rectangle The Rectangle object.
outputPhaser.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.
- Source:
- src/geom/Rectangle.js line 815
Returns:
- Type
- Phaser.Rectangle
-
<static> contains(a, x, y)
-
Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
Parameters:
Name Type Description aPhaser.Rectangle The Rectangle object.
xnumber The x coordinate of the point to test.
ynumber The y coordinate of the point to test.
- Source:
- src/geom/Rectangle.js line 837
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
- Type
- boolean
-
<static> containsPoint(a, point)
-
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 aPhaser.Rectangle The Rectangle object.
pointPhaser.Point The point object being checked. Can be Point or any object with .x and .y values.
- Source:
- src/geom/Rectangle.js line 873
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
- Type
- boolean
-
<static> containsRaw(rx, ry, rw, rh, x, y)
-
Determines whether the specified coordinates are contained within the region defined by the given raw values.
Parameters:
Name Type Description rxnumber The x coordinate of the top left of the area.
rynumber The y coordinate of the top left of the area.
rwnumber The width of the area.
rhnumber The height of the area.
xnumber The x coordinate of the point to test.
ynumber The y coordinate of the point to test.
- Source:
- src/geom/Rectangle.js line 856
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
- Type
- boolean
-
<static> containsRect(a, b)
-
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 aPhaser.Rectangle The first Rectangle object.
bPhaser.Rectangle The second Rectangle object.
- Source:
- src/geom/Rectangle.js line 886
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
- Type
- boolean
-
<static> equals(a, b)
-
Determines whether the two Rectangles are equal. This method compares the x, y, width and height properties of each Rectangle.
Parameters:
Name Type Description aPhaser.Rectangle The first Rectangle object.
bPhaser.Rectangle The second Rectangle object.
- Source:
- src/geom/Rectangle.js line 906
Returns:
A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
- Type
- boolean
-
<static> inflate(a, dx, dy)
-
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 aPhaser.Rectangle The Rectangle object.
dxnumber The amount to be added to the left side of the Rectangle.
dynumber The amount to be added to the bottom side of the Rectangle.
- Source:
- src/geom/Rectangle.js line 761
Returns:
This Rectangle object.
- Type
- Phaser.Rectangle
-
<static> inflatePoint(a, point)
-
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 aPhaser.Rectangle The Rectangle object.
pointPhaser.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.
- Source:
- src/geom/Rectangle.js line 780
Returns:
The Rectangle object.
- Type
- Phaser.Rectangle
-
<static> intersection(a, b [, output])
-
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 aPhaser.Rectangle The first Rectangle object.
bPhaser.Rectangle The second Rectangle object.
outputPhaser.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.
- Source:
- src/geom/Rectangle.js line 933
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.
- Type
- Phaser.Rectangle
-
<static> intersects(a, b)
-
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 aPhaser.Rectangle The first Rectangle object.
bPhaser.Rectangle The second Rectangle object.
- Source:
- src/geom/Rectangle.js line 960
Returns:
A value of true if the specified object intersects with this Rectangle object; otherwise false.
- Type
- boolean
-
<static> intersectsRaw(left, right, top, bottom, tolerance)
-
Determines whether the object specified intersects (overlaps) with the given values.
Parameters:
Name Type Description leftnumber The x coordinate of the left of the area.
rightnumber The right coordinate of the area.
topnumber The y coordinate of the area.
bottomnumber The bottom coordinate of the area.
tolerancenumber A tolerance value to allow for an intersection test with padding, default to 0
- Source:
- src/geom/Rectangle.js line 979
Returns:
A value of true if the specified object intersects with the Rectangle; otherwise false.
- Type
- boolean
-
<static> sameDimensions(a, b)
-
Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.
Parameters:
Name Type Description aRectangle-like The first Rectangle object.
bRectangle-like The second Rectangle object.
- Source:
- src/geom/Rectangle.js line 920
Returns:
True if the object have equivalent values for the width and height properties.
- Type
- boolean
-
<static> size(a [, output])
-
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 aPhaser.Rectangle The Rectangle object.
outputPhaser.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.
- Source:
- src/geom/Rectangle.js line 793
Returns:
The size of the Rectangle object
- Type
- Phaser.Point
-
<static> union(a, b [, output])
-
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 aPhaser.Rectangle The first Rectangle object.
bPhaser.Rectangle The second Rectangle object.
outputPhaser.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.
- Source:
- src/geom/Rectangle.js line 997
Returns:
A Rectangle object that is the union of the two Rectangles.
- Type
- Phaser.Rectangle
-
aabb(points [, out])
-
Calculates the Axis Aligned Bounding Box (or aabb) from an array of points.
Parameters:
Name Type Argument Description pointsArray.<Phaser.Point> The array of one or more points.
outPhaser.Rectangle <optional>
Optional Rectangle to store the value in, if not supplied a new Rectangle object will be created.
- Source:
- src/geom/Rectangle.js line 1016
Returns:
The new Rectangle object.
- Type
- Phaser.Rectangle
-
ceil()
-
Runs Math.ceil() on both the x and y values of this Rectangle.
- Source:
- src/geom/Rectangle.js line 163
-
ceilAll()
-
Runs Math.ceil() on the x, y, width and height values of this Rectangle.
- Source:
- src/geom/Rectangle.js line 174
-
centerOn(x, y)
-
Centers this Rectangle so that the center coordinates match the given x and y values.
Parameters:
Name Type Description xnumber The x coordinate to place the center of the Rectangle at.
ynumber The y coordinate to place the center of the Rectangle at.
- Source:
- src/geom/Rectangle.js line 122
Returns:
This Rectangle object
- Type
- Phaser.Rectangle
-
clone( [output])
-
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 outputPhaser.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.
- Source:
- src/geom/Rectangle.js line 259
Returns:
- Type
- Phaser.Rectangle
-
contains(x, y)
-
Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
Parameters:
Name Type Description xnumber The x coordinate of the point to test.
ynumber The y coordinate of the point to test.
- Source:
- src/geom/Rectangle.js line 271
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
- Type
- boolean
-
containsRect(b)
-
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 bPhaser.Rectangle The second Rectangle object.
- Source:
- src/geom/Rectangle.js line 284
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
- Type
- boolean
-
copyFrom(source)
-
Copies the x, y, width and height properties from any given object to this Rectangle.
Parameters:
Name Type Description sourceany The object to copy from.
- Source:
- src/geom/Rectangle.js line 187
Returns:
This Rectangle object.
- Type
- Phaser.Rectangle
-
copyTo(source)
-
Copies the x, y, width and height properties from this Rectangle to any given object.
Parameters:
Name Type Description sourceany The object to copy to.
- Source:
- src/geom/Rectangle.js line 199
Returns:
This object.
- Type
- object
-
equals(b)
-
Determines whether the two Rectangles are equal. This method compares the x, y, width and height properties of each Rectangle.
Parameters:
Name Type Description bPhaser.Rectangle The second Rectangle object.
- Source:
- src/geom/Rectangle.js line 297
Returns:
A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
- Type
- boolean
-
floor()
-
Runs Math.floor() on both the x and y values of this Rectangle.
- Source:
- src/geom/Rectangle.js line 139
-
floorAll()
-
Runs Math.floor() on the x, y, width and height values of this Rectangle.
- Source:
- src/geom/Rectangle.js line 150
-
getPoint( [position] [, out])
-
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_CENTERandPhaser.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 positioninteger <optional>
One of the Phaser position constants, such as
Phaser.TOP_RIGHT.outPhaser.Point <optional>
A Phaser.Point that the values will be set in. If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object.
- Source:
- src/geom/Rectangle.js line 386
Returns:
An object containing the point in its
xandyproperties.- Type
- Phaser.Point
-
inflate(dx, dy)
-
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 dxnumber The amount to be added to the left side of the Rectangle.
dynumber The amount to be added to the bottom side of the Rectangle.
- Source:
- src/geom/Rectangle.js line 216
Returns:
This Rectangle object.
- Type
- Phaser.Rectangle
-
intersection(b, out)
-
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 bPhaser.Rectangle The second Rectangle object.
outPhaser.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.
- Source:
- src/geom/Rectangle.js line 310
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.
- Type
- Phaser.Rectangle
-
intersects(b)
-
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 bPhaser.Rectangle The second Rectangle object.
- Source:
- src/geom/Rectangle.js line 323
Returns:
A value of true if the specified object intersects with this Rectangle object; otherwise false.
- Type
- boolean
-
intersectsRaw(left, right, top, bottom, tolerance)
-
Determines whether the coordinates given intersects (overlaps) with this Rectangle.
Parameters:
Name Type Description leftnumber The x coordinate of the left of the area.
rightnumber The right coordinate of the area.
topnumber The y coordinate of the area.
bottomnumber The bottom coordinate of the area.
tolerancenumber A tolerance value to allow for an intersection test with padding, default to 0
- Source:
- src/geom/Rectangle.js line 337
Returns:
A value of true if the specified object intersects with the Rectangle; otherwise false.
- Type
- boolean
-
offset(dx, dy)
-
Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
Parameters:
Name Type Description dxnumber Moves the x value of the Rectangle object by this amount.
dynumber Moves the y value of the Rectangle object by this amount.
- Source:
- src/geom/Rectangle.js line 55
Returns:
This Rectangle object.
- Type
- Phaser.Rectangle
-
offsetPoint(point)
-
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 pointPhaser.Point A Point object to use to offset this Rectangle object.
- Source:
- src/geom/Rectangle.js line 71
Returns:
This Rectangle object.
- Type
- Phaser.Rectangle
-
random( [out])
-
Returns a uniformly distributed random point from anywhere within this Rectangle.
Parameters:
Name Type Argument Description outPhaser.Point | object <optional>
A Phaser.Point, or any object with public x/y properties, that the values will be set in. If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object.
- Source:
- src/geom/Rectangle.js line 367
Returns:
An object containing the random point in its
xandyproperties.- Type
- Phaser.Point
-
resize(width, height)
-
Resize the Rectangle by providing a new width and height. The x and y positions remain unchanged.
Parameters:
Name Type Description widthnumber The width of the Rectangle. Should always be either zero or a positive value.
heightnumber The height of the Rectangle. Should always be either zero or a positive value.
- Source:
- src/geom/Rectangle.js line 241
Returns:
This Rectangle object
- Type
- Phaser.Rectangle
-
scale(x [, y])
-
Scales the width and height of this Rectangle by the given amounts.
Parameters:
Name Type Argument Description xnumber 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.
ynumber <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.
- Source:
- src/geom/Rectangle.js line 103
Returns:
This Rectangle object
- Type
- Phaser.Rectangle
-
setTo(x, y, width, height)
-
Sets the members of Rectangle to the specified values.
Parameters:
Name Type Description xnumber The x coordinate of the top-left corner of the Rectangle.
ynumber The y coordinate of the top-left corner of the Rectangle.
widthnumber The width of the Rectangle. Should always be either zero or a positive value.
heightnumber The height of the Rectangle. Should always be either zero or a positive value.
- Source:
- src/geom/Rectangle.js line 83
Returns:
This Rectangle object
- Type
- Phaser.Rectangle
-
size( [output])
-
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 outputPhaser.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.
- Source:
- src/geom/Rectangle.js line 229
Returns:
The size of the Rectangle object.
- Type
- Phaser.Point
-
toString()
-
Returns a string representation of this object.
- Source:
- src/geom/Rectangle.js line 439
Returns:
A string representation of the instance.
- Type
- string
-
union(b [, out])
-
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 bPhaser.Rectangle The second Rectangle object.
outPhaser.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.
- Source:
- src/geom/Rectangle.js line 354
Returns:
A Rectangle object that is the union of the two Rectangles.
- Type
- Phaser.Rectangle