phaser - v4.0.0-rc.4
    Preparing search index...

    Encapsulates a 2D rectangle defined by its corner point in the top-left and its extends in x (width) and y (height)

    Index

    Constructors

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

    Properties

    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.

    Methods

    • 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

    • 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

    • 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

    • 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

    • 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

    • 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

    • 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

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

      Returns boolean

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

      Returns this

    • 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

    • 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

    • 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

    • 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

    • 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

    • 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

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

      Parameters

      • rect: Geom.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

    • 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

      • rect: Geom.Rectangle

        The Rectangle object to be decomposed.

      • Optionalout: any[]

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

      Returns any[]

    • 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: Geom.Rectangle

        The source rectangle to envelop the target in.

      Returns O

    • 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: Geom.Rectangle

        The source rectangle to envelope the target in.

      Returns O

    • 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

    • 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

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

    • 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

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

    • 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: Geom.Rectangle

        The Rectangle object to get the points from.

      • step: number

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

      • quantity: number

        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.

      • Optionalout: O

        An optional array to store the points in.

      Returns O

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

    • 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

    • 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: Geom.Rectangle

        The first Rectangle to get the intersection from.

      • rectB: Geom.Rectangle

        The second Rectangle to get the intersection from.

      • Optionalout: Geom.Rectangle

        A Rectangle to store the intersection results in.

      Returns O

    • Returns an array of Vector2 points from the perimeter of the Rectangle, where each point is spaced out based on either the step value, or the quantity.

      Type Parameters

      Parameters

      • rect: Geom.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

    • 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: Math.Vector2[]

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

      Returns O

    • 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: Geom.Rectangle

        Rectangle that will be merged into target rectangle.

      Returns O

    • 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

    • Nudges (translates) the top left corner of a Rectangle by a given offset.

      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

    • 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

      Returns boolean

    • Returns a Point from the perimeter of a Rectangle based on the given angle.

      Type Parameters

      Parameters

      • rectangle: Geom.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

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

      Type Parameters

      Parameters

      • outer: Geom.Rectangle

        The outer Rectangle to get the random point within.

      • inner: Geom.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

    • Scales the width and height of this Rectangle by the given amounts.

      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 amount 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