PokéRogue
    Preparing search index...

    A Rectangle is an axis-aligned region of 2D space defined by its top-left corner position (x, y) and its dimensions (width, height). It is one of the core geometric primitives in Phaser and is used extensively throughout the framework for bounds checking, camera viewports, hit areas, culling regions, and UI layout.

    Rectangles support containment tests, perimeter point sampling, and many other geometric operations available via the Phaser.Geom.Rectangle static methods. The left, right, top, bottom, centerX, and centerY properties provide convenient access to derived positional values and can be set directly to reposition or resize the Rectangle.

    Index
    • Parameters

      • Optionalx: number

        The X coordinate of the top left corner of the Rectangle. Default 0.

      • Optionaly: number

        The Y coordinate of the top left corner of the Rectangle. Default 0.

      • Optionalwidth: number

        The width of the Rectangle. Default 0.

      • Optionalheight: number

        The height of the Rectangle. Default 0.

      Returns Rectangle

    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.

    centerX: number

    The x coordinate of the center of the Rectangle.

    centerY: number

    The y coordinate of the center of the Rectangle.

    height: number

    The height of the Rectangle, i.e. the distance between its top side (defined by y) and its bottom side.

    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.

    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.

    type: number

    The geometry constant type of this object: GEOM_CONST.RECTANGLE. Used for fast type comparisons.

    width: number

    The width of the Rectangle, i.e. the distance between its left side (defined by x) and its right side.

    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.

    • Checks if the given point is inside the Rectangle's bounds.

      Parameters

      • x: number

        The X coordinate of the point to check.

      • y: number

        The Y coordinate of the point to check.

      Returns boolean

      true if the point is within the Rectangle's bounds, otherwise false.

    • Returns a Line object that corresponds to the top of this Rectangle.

      Type Parameters

      Parameters

      • Optionalline: O

        A Line object to set the results in. If undefined a new Line will be created.

      Returns O

      A Line object that corresponds to the top of this Rectangle.

    • Returns a Line object that corresponds to the right of this Rectangle.

      Type Parameters

      Parameters

      • Optionalline: O

        A Line object to set the results in. If undefined a new Line will be created.

      Returns O

      A Line object that corresponds to the right of this Rectangle.

    • Returns a Line object that corresponds to the bottom of this Rectangle.

      Type Parameters

      Parameters

      • Optionalline: O

        A Line object to set the results in. If undefined a new Line will be created.

      Returns O

      A Line object that corresponds to the bottom of this Rectangle.

    • Returns a Line object that corresponds to the left of this Rectangle.

      Type Parameters

      Parameters

      • Optionalline: O

        A Line object to set the results in. If undefined a new Line will be created.

      Returns O

      A Line object that corresponds to the left of this Rectangle.

    • Calculates the coordinates of a point at a certain position on the Rectangle's perimeter.

      The position is a fraction between 0 and 1 which defines how far into the perimeter the point is.

      A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side.

      Type Parameters

      Parameters

      • position: number

        The normalized distance into the Rectangle's perimeter to return.

      • Optionaloutput: O

        A Vector2 instance to update with the x and y coordinates of the point.

      Returns O

      The updated output object, or a new Vector2 if no output object was given.

    • Returns an array of points from the perimeter of the Rectangle, each spaced out based on the quantity or step required.

      Type Parameters

      Parameters

      • quantity: number

        The number of points to return. Set to false or 0 to return an arbitrary number of points (perimeter / stepRate) evenly spaced around the Rectangle based on the stepRate.

      • OptionalstepRate: number

        If quantity is 0, determines the normalized distance between each returned point.

      • Optionaloutput: O

        An array to which to append the points.

      Returns O

      The modified output array, or a new array if none was provided.

    • Returns a random point within the Rectangle's bounds.

      Type Parameters

      Parameters

      • Optionalvec: Vector2

        The object in which to store the x and y coordinates of the point.

      Returns O

      The updated vec, or a new Vector2 if none was provided.

    • Determines if the Rectangle is empty. A Rectangle is empty if its width or height is less than or equal to 0.undefined

      Returns boolean

      true if the Rectangle is empty, otherwise false.

    • Resets the position, width, and height of the Rectangle to 0.undefined

      Returns this

      This Rectangle object.

    • Sets the position of the Rectangle.

      Parameters

      • x: number

        The X coordinate of the top left corner of the Rectangle.

      • Optionaly: number

        The Y coordinate of the top left corner of the Rectangle. Default x.

      Returns this

      This Rectangle object.

    • Sets the width and height of the Rectangle.

      Parameters

      • width: number

        The width to set the Rectangle to.

      • Optionalheight: number

        The height to set the Rectangle to. Default width.

      Returns this

      This Rectangle object.

    • Sets the position, width, and height of the Rectangle.

      Parameters

      • x: number

        The X coordinate of the top left corner of the Rectangle.

      • y: number

        The Y coordinate of the top left corner of the Rectangle.

      • width: number

        The width of the Rectangle.

      • height: number

        The height of the Rectangle.

      Returns this

      This Rectangle object.

    • Calculates the area of the given Rectangle object.

      Parameters

      • rect: Rectangle

        The rectangle to calculate the area of.

      Returns number

      The area of the Rectangle object.

    • Rounds a Rectangle's position up to the smallest integer greater than or equal to each current coordinate.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle to adjust.

      Returns O

      The adjusted Rectangle.

    • Rounds a Rectangle's position and size up to the smallest integer greater than or equal to each respective value.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle to modify.

      Returns O

      The modified Rectangle.

    • Moves the top-left corner of a Rectangle so that its center is at the given coordinates.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle to be centered.

      • x: number

        The X coordinate of the Rectangle's center.

      • y: number

        The Y coordinate of the Rectangle's center.

      Returns O

      The centered rectangle.

    • Creates a new Rectangle which is identical to the given one.

      Parameters

      Returns Rectangle

      The newly created Rectangle, which is separate from the given one.

    • Checks if a given point is inside a Rectangle's bounds.

      Parameters

      • rect: Rectangle

        The Rectangle to check.

      • x: number

        The X coordinate of the point to check.

      • y: number

        The Y coordinate of the point to check.

      Returns boolean

      true if the point is within the Rectangle's bounds, otherwise false.

    • Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.

      Parameters

      • rect: Rectangle

        The Rectangle object.

      • vec: Vector2

        The Vector2 object to check the coordinates of.

      Returns boolean

      A value of true if the Rectangle object contains the specified point, otherwise false.

    • Tests if one rectangle fully contains another. A rectangle is considered fully contained if all four of its edges (left, right, top, and bottom) lie strictly within the bounds of the outer rectangle. Rectangles that merely touch or overlap are not considered contained.

      Parameters

      • rectA: Rectangle

        The outer rectangle to test as the container.

      • rectB: Rectangle

        The inner rectangle to test for full containment within rectA.

      Returns boolean

      True only if rectA fully contains rectB.

    • Copy the values of one Rectangle to a destination Rectangle.

      Type Parameters

      Parameters

      • source: Rectangle

        The source Rectangle to copy the values from.

      • dest: O

        The destination Rectangle to copy the values to.

      Returns O

      The destination Rectangle.

    • Creates an array of plain {x, y} point objects for each of the four corners of a Rectangle, in the order: top-left, top-right, bottom-right, bottom-left. If an output array is provided, each point object will be pushed to the end of it, otherwise a new array will be created and returned.

      Parameters

      • rect: Rectangle

        The Rectangle object to be decomposed.

      • Optionalout: any[]

        If provided, each point will be added to this array.

      Returns any[]

      Will return the array you specified or a new array containing the points of the Rectangle.

    • Compares the x, y, width and height properties of two rectangles. Returns true only if all four values match exactly using strict equality. This function does not consider rectangles with the same area but different positions or dimensions to be equal.

      Parameters

      • rect: Rectangle

        The first rectangle to compare.

      • toCompare: Rectangle

        The second rectangle to compare against.

      Returns boolean

      true if the rectangles' properties are an exact match, otherwise false.

    • 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 FitOutside function, there may be some space inside the source area not covered.

      Type Parameters

      Parameters

      • target: O

        The target rectangle to adjust.

      • source: Rectangle

        The source rectangle to envelop the target in.

      Returns O

      The modified target rectangle instance.

    • 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 FitInside function, the target rectangle may extend further out than the source.

      Type Parameters

      Parameters

      • target: O

        The target rectangle to adjust.

      • source: Rectangle

        The source rectangle to envelope the target in.

      Returns O

      The modified target rectangle instance.

    • Rounds down (floors) the top left X and Y coordinates of the given Rectangle to the largest integer less than or equal to them

      Type Parameters

      Parameters

      • rect: O

        The rectangle to floor the top left X and Y coordinates of

      Returns O

      The rectangle that was passed to this function with its coordinates floored.

    • Rounds a Rectangle's position and size down to the largest integer less than or equal to each current coordinate or dimension.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle to adjust.

      Returns O

      The adjusted Rectangle.

    • Constructs a new Rectangle or repositions and resizes an existing Rectangle so that all of the given points are on or within its bounds.

      The points parameter is an array of Point-like objects:

      const points = [
      [100, 200],
      [200, 400],
      { x: 30, y: 60 }
      ]

      Type Parameters

      Parameters

      • points: any[]

        An array of points (either arrays with two elements corresponding to the X and Y coordinate or an object with public x and y properties) which should be surrounded by the Rectangle.

      • Optionalout: O

        Optional Rectangle to adjust.

      Returns O

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

    • Create the smallest Rectangle containing two coordinate pairs.

      Type Parameters

      Parameters

      • x1: number

        The X coordinate of the first point.

      • y1: number

        The Y coordinate of the first point.

      • x2: number

        The X coordinate of the second point.

      • y2: number

        The Y coordinate of the second point.

      • Optionalout: O

        Optional Rectangle to adjust.

      Returns O

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

    • Calculates the width/height ratio of a rectangle.

      Parameters

      Returns number

      The width/height ratio of the rectangle.

    • Returns the center of a Rectangle as a Point.

      Type Parameters

      Parameters

      • rect: Rectangle

        The Rectangle to get the center of.

      • Optionalout: O

        Optional Vector2 object to update with the center coordinates.

      Returns O

      The modified out object, or a new Vector2 if none was provided.

    • Calculates the coordinates of a point at a certain position on the Rectangle's perimeter.

      The position is a fraction between 0 and 1 which defines how far into the perimeter the point is.

      A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side.

      Type Parameters

      Parameters

      • rectangle: Rectangle

        The Rectangle to get the perimeter point from.

      • position: number

        The normalized distance into the Rectangle's perimeter to return.

      • Optionalout: O

        A Vector2 object to update with the x and y coordinates of the point.

      Returns O

      The updated out object, or a new Vector2 if no out object was given.

    • Return an array of Vector2 points from the perimeter of the rectangle, each spaced out based on the quantity or step required.

      Type Parameters

      Parameters

      • rectangle: Rectangle

        The Rectangle object to get the points from.

      • quantity: number

        The number of evenly spaced points from the rectangle's perimeter to return. If falsey, stepRate param will be used to calculate the number of points.

      • stepRate: number

        Step between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive.

      • Optionalout: O

        An optional array to store the points in.

      Returns O

      An array of Vector2 points from the perimeter of the rectangle.

    • Returns the size of the Rectangle, expressed as a Vector2 object. With the value of the width as the x property and the height as the y property.

      Type Parameters

      Parameters

      • rect: Rectangle

        The Rectangle to get the size from.

      • Optionalout: O

        The Vector2 object to store the size in. If not given, a new Vector2 instance is created.

      Returns O

      A Vector2 object where x holds the width and y holds the height of the Rectangle.

    • 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.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle to inflate.

      • x: number

        How many pixels the left and the right side should be moved by horizontally.

      • y: number

        How many pixels the top and the bottom side should be moved by vertically.

      Returns O

      The inflated Rectangle.

    • Takes two Rectangles and first checks to see if they intersect. If they intersect it will return the area of intersection in the out Rectangle. If they do not intersect, the out Rectangle will have a width and height of zero.

      Type Parameters

      Parameters

      • rectA: Rectangle

        The first Rectangle to get the intersection from.

      • rectB: Rectangle

        The second Rectangle to get the intersection from.

      • Optionalout: Rectangle

        A Rectangle to store the intersection results in.

      Returns O

      The intersection result. If the width and height are zero, no intersection occurred.

    • Returns an array of Vector2 points evenly distributed around the perimeter of the Rectangle. This is commonly used to create a "marching ants" selection effect, where the returned points are used to animate a dashed outline that appears to march around the border of the rectangle.

      You can control the spacing of the points either by providing a pixel step distance between each point, or by specifying the total quantity of points to distribute evenly around the full perimeter. If both are omitted, an empty array is returned. If step is provided, quantity is derived from the perimeter length divided by the step. If only quantity is provided, the step is derived instead.

      Type Parameters

      Parameters

      • rect: Rectangle

        The Rectangle to get the perimeter points from.

      • Optionalstep: number

        The distance between each point of the perimeter. Set to null if you wish to use the quantity parameter instead.

      • Optionalquantity: number

        The total number of points to return. The step is then calculated based on the length of the Rectangle, divided by this value.

      • Optionalout: O

        An array in which the perimeter points will be stored. If not given, a new array instance is created.

      Returns O

      An array containing the perimeter points from the Rectangle.

    • 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.

      Type Parameters

      Parameters

      • target: O

        The Rectangle which should be merged.

      • points: Vector2[]

        An array of Vector2 objects which should be merged with the Rectangle.

      Returns O

      The modified Rectangle.

    • Merges the source rectangle into the target rectangle and returns the target. Neither rectangle should have a negative width or height.

      Type Parameters

      Parameters

      • target: O

        Target rectangle. Will be modified to include source rectangle.

      • source: Rectangle

        Rectangle that will be merged into target rectangle.

      Returns O

      Modified target rectangle that contains source rectangle.

    • Merges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds.

      Type Parameters

      Parameters

      • target: O

        The Rectangle which should be merged and modified.

      • x: number

        The X coordinate of the point which should be merged.

      • y: number

        The Y coordinate of the point which should be merged.

      Returns O

      The modified target Rectangle.

    • Translates a Rectangle by the given horizontal and vertical amounts, moving its position while preserving its size.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle to adjust.

      • x: number

        The distance to move the Rectangle horizontally.

      • y: number

        The distance to move the Rectangle vertically.

      Returns O

      The adjusted Rectangle.

    • Translates the top-left corner of a Rectangle by the coordinates of a translation vector.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle to adjust.

      • vec: Vector2

        The Vector2 point whose coordinates should be used as an offset.

      Returns O

      The adjusted Rectangle.

    • 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

      • rectA: Rectangle

        The first Rectangle to check.

      • rectB: Rectangle

        The second Rectangle to check.

      Returns boolean

      true if the two Rectangles overlap, false otherwise.

    • Calculates the perimeter of a Rectangle.

      Parameters

      Returns number

      The perimeter of the Rectangle, equal to (width * 2) + (height * 2).

    • Returns a point from the perimeter of a Rectangle based on the given angle, measured in degrees from the center of the Rectangle.

      Type Parameters

      Parameters

      • rectangle: Rectangle

        The Rectangle to get the perimeter point from.

      • angle: number

        The angle of the point, in degrees.

      • Optionalout: O

        The Vector2 object to store the position in. If not given, a new Vector2 instance is created.

      Returns O

      A Vector2 object holding the coordinates of the point on the Rectangle's perimeter.

    • Returns a random point within a Rectangle.

      Type Parameters

      Parameters

      • rect: Rectangle

        The Rectangle to return a point from.

      • out: O

        The object to update with the point's coordinates.

      Returns O

      The modified out object, or a new Point if none was provided.

    • Calculates a random point that lies within the outer Rectangle, but outside of the inner Rectangle. The inner Rectangle must be fully contained within the outer rectangle for a point to be generated. If inner is not fully contained within outer, the function returns the out vector unchanged.

      Type Parameters

      Parameters

      • outer: Rectangle

        The outer Rectangle to get the random point within.

      • inner: Rectangle

        The inner Rectangle to exclude from the returned point.

      • Optionalout: O

        A Vector2 object to store the result in. If not specified, a new Vector2 will be created.

      Returns O

      A Vector2 object containing the random values in its x and y properties.

    • Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.

      Parameters

      • rect: Rectangle

        The first Rectangle object.

      • toCompare: Rectangle

        The second Rectangle object.

      Returns boolean

      true if the objects have equivalent values for the width and height properties, otherwise false.

    • Scales the width and height of the given Rectangle by the given factors.

      Type Parameters

      Parameters

      • rect: O

        The Rectangle object that will be scaled by the specified amount(s).

      • x: number

        The factor by which to scale the rectangle horizontally.

      • y: number

        The factor by which to scale the rectangle vertically. If this is not specified, the rectangle will be scaled by the factor x in both directions.

      Returns O

      The rectangle object with updated width and height properties as calculated from the scaling factor(s).

    • 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.

      Type Parameters

      Parameters

      • rectA: Rectangle

        The first Rectangle to use.

      • rectB: Rectangle

        The second Rectangle to use.

      • Optionalout: O

        The Rectangle to store the union in.

      Returns O

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