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)
-
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
- 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 rectPhaser.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 rectPhaser.Geom.Rectangle The Rectangle to adjust.
- Since: 3.0.0
- Source: src/geom/rectangle/Ceil.js (Line 7)
Returns:
The adjusted 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 rectPhaser.Geom.Rectangle The Rectangle to modify.
- Since: 3.0.0
- Source: src/geom/rectangle/CeilAll.js (Line 7)
Returns:
The modified 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 rectPhaser.Geom.Rectangle The Rectangle to be centered.
xnumber The X coordinate of the Rectangle's center.
ynumber The Y coordinate of the Rectangle's center.
- Since: 3.0.0
- Source: src/geom/rectangle/CenterOn.js (Line 9)
Returns:
The centered rectangle.
-
<static> Clone(source)
-
Creates a new Rectangle which is identical to the given one.
Parameters:
Name Type Description sourcePhaser.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.
-
<static> Contains(rect, x, y)
-
Checks if a given point is inside a Rectangle's bounds.
Parameters:
Name Type Description rectPhaser.Geom.Rectangle The Rectangle to check.
xnumber The X coordinate of the point to check.
ynumber The Y coordinate of the point to check.
- Since: 3.0.0
- Source: src/geom/rectangle/Contains.js (Line 7)
Returns:
trueif the point is within the Rectangle's bounds, otherwisefalse.- 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 rectPhaser.Geom.Rectangle The Rectangle object.
pointPhaser.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 rectAPhaser.Geom.Rectangle The first rectangle.
rectBPhaser.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 sourcePhaser.Geom.Rectangle The source Rectangle to copy the values from.
destPhaser.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.
-
<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 rectPhaser.Geom.Rectangle The Rectangle object to be decomposed.
outarray <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,widthandheightproperties of two rectangles.Parameters:
Name Type Description rectPhaser.Geom.Rectangle Rectangle A
toComparePhaser.Geom.Rectangle Rectangle B
- Since: 3.0.0
- Source: src/geom/rectangle/Equals.js (Line 7)
Returns:
trueif the rectangles' properties are an exact match, otherwisefalse.- 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
FitOutsidefunction, there may be some space inside the source area not covered.Parameters:
Name Type Description targetPhaser.Geom.Rectangle The target rectangle to adjust.
sourcePhaser.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.
-
<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
FitInsidefunction, the target rectangle may extend further out than the source.Parameters:
Name Type Description targetPhaser.Geom.Rectangle The target rectangle to adjust.
sourcePhaser.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.
-
<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 rectPhaser.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.
-
<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 rectPhaser.Geom.Rectangle The Rectangle to adjust.
- Since: 3.0.0
- Source: src/geom/rectangle/FloorAll.js (Line 7)
Returns:
The adjusted 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 pointsarray An array of points (either arrays with two elements corresponding to the X and Y coordinate or an object with public
xandyproperties) which should be surrounded by the Rectangle.outPhaser.Geom.Rectangle <optional>
Optional Rectangle to adjust.
- Since: 3.0.0
- Source: src/geom/rectangle/FromPoints.js (Line 18)
Returns:
The adjusted
outRectangle, or a new Rectangle if none was provided. -
<static> FromXY(x1, y1, x2, y2 [, out])
-
Create the smallest Rectangle containing two coordinate pairs.
Parameters:
Name Type Argument Description x1number The X coordinate of the first point.
y1number The Y coordinate of the first point.
x2number The X coordinate of the second point.
y2number The Y coordinate of the second point.
outPhaser.Geom.Rectangle <optional>
Optional Rectangle to adjust.
- Since: 3.23.0
- Source: src/geom/rectangle/FromXY.js (Line 9)
Returns:
The adjusted
outRectangle, or a new Rectangle if none was provided. -
<static> GetAspectRatio(rect)
-
Calculates the width/height ratio of a rectangle.
Parameters:
Name Type Description rectPhaser.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 rectPhaser.Geom.Rectangle The Rectangle to get the center of.
outPhaser.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
outobject, 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
positionon the Rectangle's perimeter.The
positionis 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 rectanglePhaser.Geom.Rectangle The Rectangle to get the perimeter point from.
positionnumber The normalized distance into the Rectangle's perimeter to return.
outPhaser.Geom.Point | object <optional>
An object to update with the
xandycoordinates of the point.- Since: 3.0.0
- Source: src/geom/rectangle/GetPoint.js (Line 10)
Returns:
The updated
outputobject, or a new Point if nooutputobject 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 rectanglePhaser.Geom.Rectangle The Rectangle object to get the points from.
stepnumber Step between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive.
quantitynumber 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.
outarray | 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
widthas thexproperty and theheightas theyproperty.Parameters:
Name Type Argument Description rectPhaser.Geom.Rectangle The Rectangle to get the size from.
outPhaser.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
xholds the width andyholds 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 rectPhaser.Geom.Rectangle The Rectangle to inflate.
xnumber How many pixels the left and the right side should be moved by horizontally.
ynumber 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.
-
<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
outRectangle. If they do not intersect, theoutRectangle will have a width and height of zero.Parameters:
Name Type Argument Description rectAPhaser.Geom.Rectangle The first Rectangle to get the intersection from.
rectBPhaser.Geom.Rectangle The second Rectangle to get the intersection from.
outPhaser.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.
-
<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
stepvalue, or thequantity.Parameters:
Name Type Argument Description rectPhaser.Geom.Rectangle The Rectangle to get the perimeter points from.
stepnumber <optional>
The distance between each point of the perimeter. Set to
nullif you wish to use thequantityparameter instead.quantitynumber <optional>
The total number of points to return. The step is then calculated based on the length of the Rectangle, divided by this value.
outarray | 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 targetPhaser.Geom.Rectangle The Rectangle which should be merged.
pointsArray.<Phaser.Geom.Point> An array of Points (or any object with public
xandyproperties) which should be merged with the Rectangle.- Since: 3.0.0
- Source: src/geom/rectangle/MergePoints.js (Line 7)
Returns:
The modified 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 targetPhaser.Geom.Rectangle Target rectangle. Will be modified to include source rectangle.
sourcePhaser.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.
-
<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 targetPhaser.Geom.Rectangle The Rectangle which should be merged and modified.
xnumber The X coordinate of the point which should be merged.
ynumber 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
targetRectangle. -
<static> Offset(rect, x, y)
-
Nudges (translates) the top left corner of a Rectangle by a given offset.
Parameters:
Name Type Description rectPhaser.Geom.Rectangle The Rectangle to adjust.
xnumber The distance to move the Rectangle horizontally.
ynumber The distance to move the Rectangle vertically.
- Since: 3.0.0
- Source: src/geom/rectangle/Offset.js (Line 7)
Returns:
The adjusted 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 rectPhaser.Geom.Rectangle The Rectangle to adjust.
pointPhaser.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.
-
<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 rectAPhaser.Geom.Rectangle The first Rectangle to check.
rectBPhaser.Geom.Rectangle The second Rectangle to check.
- Since: 3.0.0
- Source: src/geom/rectangle/Overlaps.js (Line 7)
Returns:
trueif the two Rectangles overlap,falseotherwise.- Type
- boolean
-
<static> Perimeter(rect)
-
Calculates the perimeter of a Rectangle.
Parameters:
Name Type Description rectPhaser.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 rectanglePhaser.Geom.Rectangle The Rectangle to get the perimeter point from.
anglenumber The angle of the point, in degrees.
outPhaser.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 rectPhaser.Geom.Rectangle The Rectangle to return a point from.
outPhaser.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
outobject, 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
outerRectangle, but outside of theinnerRectangle. The inner Rectangle must be fully contained within the outer rectangle.Parameters:
Name Type Argument Description outerPhaser.Geom.Rectangle The outer Rectangle to get the random point within.
innerPhaser.Geom.Rectangle The inner Rectangle to exclude from the returned point.
outPhaser.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
xandyproperties.- 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 rectPhaser.Geom.Rectangle The first Rectangle object.
toComparePhaser.Geom.Rectangle The second Rectangle object.
- Since: 3.15.0
- Source: src/geom/rectangle/SameDimensions.js (Line 7)
Returns:
trueif the objects have equivalent values for thewidthandheightproperties, otherwisefalse.- Type
- boolean
-
<static> Scale(rect, x, y)
-
Scales the width and height of this Rectangle by the given amounts.
Parameters:
Name Type Description rectPhaser.Geom.Rectangle The
Rectangleobject that will be scaled by the specified amount(s).xnumber The factor by which to scale the rectangle horizontally.
ynumber The amount by which to scale the rectangle vertically. If this is not specified, the rectangle will be scaled by the factor
xin both directions.- Since: 3.0.0
- Source: src/geom/rectangle/Scale.js (Line 9)
Returns:
The rectangle object with updated
widthandheightproperties as calculated from the scaling factor(s). -
<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 rectAPhaser.Geom.Rectangle The first Rectangle to use.
rectBPhaser.Geom.Rectangle The second Rectangle to use.
outPhaser.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
outRectangle, or a new Rectangle if none was provided. -
contains(x, y)
-
Checks if the given point is inside the Rectangle's bounds.
Parameters:
Name Type Description xnumber The X coordinate of the point to check.
ynumber The Y coordinate of the point to check.
- Since: 3.0.0
- Source: src/geom/rectangle/Rectangle.js (Line 92)
Returns:
trueif the point is within the Rectangle's bounds, otherwisefalse.- Type
- boolean
-
getLineA( [line])
-
Returns a Line object that corresponds to the top of this Rectangle.
Parameters:
Name Type Argument Description linePhaser.Geom.Line <optional>
A Line object to set the results in. If
undefineda 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 linePhaser.Geom.Line <optional>
A Line object to set the results in. If
undefineda 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 linePhaser.Geom.Line <optional>
A Line object to set the results in. If
undefineda 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 linePhaser.Geom.Line <optional>
A Line object to set the results in. If
undefineda 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
positionon the Rectangle's perimeter.The
positionis 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 positionnumber The normalized distance into the Rectangle's perimeter to return.
outputPhaser.Geom.Point | object <optional>
An object to update with the
xandycoordinates of the point.- Since: 3.0.0
- Source: src/geom/rectangle/Rectangle.js (Line 108)
Returns:
The updated
outputobject, or a new Point if nooutputobject 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 quantitynumber The number of points to return. Set to
falseor 0 to return an arbitrary number of points (perimeter / stepRate) evenly spaced around the Rectangle based on thestepRate.stepRatenumber <optional>
If
quantityis 0, determines the normalized distance between each returned point.outputarray | 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
outputarray, 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 pointPhaser.Geom.Point <optional>
The object in which to store the
xandycoordinates 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:
trueif 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.
-
setPosition(x [, y])
-
Sets the position of the Rectangle.
Parameters:
Name Type Argument Default Description xnumber The X coordinate of the top left corner of the Rectangle.
ynumber <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.
-
setSize(width [, height])
-
Sets the width and height of the Rectangle.
Parameters:
Name Type Argument Default Description widthnumber The width to set the Rectangle to.
heightnumber <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.
-
setTo(x, y, width, height)
-
Sets the position, width, and height of the Rectangle.
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.
heightnumber The height of the Rectangle.
- Since: 3.0.0
- Source: src/geom/rectangle/Rectangle.js (Line 166)
Returns:
This Rectangle object.
