melonJS
    Preparing search index...

    Class Rect

    A rectangle object.

    Hierarchy (View Summary)

    Index
    collisionMask?: number
    collisionType?: number

    Optional per-shape collision settings, honoured by Body#addShape and defaulted there. Declared rather than initialized: the body writes them when the shape joins it, so a class field here would emit an undefined own property on every shape ever built. See addShape for the table of defaults and what each one does.

    Body#addShape

    edges: Vector2d[]

    The edges here are the direction of the nth edge of the polygon, relative to the nth point. If you want to draw a given edge from the edge value, you must first translate to the position of the starting point.

    indices: number[]

    a list of indices for all vertices composing this polygon, filled in by Polygon#getIndices and invalidated by Polygon#recalc.

    A subclass may repurpose this name for geometry of its own: a Mesh holds a GPU index buffer here, a typed array rather than a plain one. recalc therefore only clears the slot when it owns it — anything else reading it should check what it got.

    isActive?: boolean

    false takes this shape out of collision without removing it

    isTrigger?: boolean

    true reports contacts but skips the position correction

    points: Vector2d[]

    Array of points defining the Polygon
    Note: If you manually change points, you must call recalcafterwards so that the changes get applied correctly.

    origin point of the Polygon

    type: string = "Rectangle"

    The shape type (used internally).

    • center the rectangle position around the given coordinates

      Parameters

      • x: number

        the x coordinate around which to center this rectangle

      • y: number

        the y coordinate around which to center this rectangle

      Returns Rect

      this rectangle

    • Returns true if the polygon contains the given point.
      (Note: it is highly recommended to first do a hit test on the corresponding
      bounding rect, as the function can be highly consuming with complex shapes)

      Parameters

      • x: number

        x coordinate or a vector point to check

      • y: number

        y coordinate

      Returns boolean

      True if the polygon contain the point, otherwise false

      if (polygon.contains(10, 10)) {
      // do something
      }
      // or
      if (polygon.contains(myVector2d)) {
      // do something
      }
    • Returns true if the polygon contains the given point.
      (Note: it is highly recommended to first do a hit test on the corresponding
      bounding rect, as the function can be highly consuming with complex shapes)

      Parameters

      Returns boolean

      True if the polygon contain the point, otherwise false

      if (polygon.contains(10, 10)) {
      // do something
      }
      // or
      if (polygon.contains(myVector2d)) {
      // do something
      }
    • Returns true if the rectangle contains the given rectangle

      Parameters

      • rectangle: Rect

        rectangle to test

      Returns boolean

      True if the rectangle contain the given rectangle, otherwise false

      if (rect.containsRectangle(myRect)) {
      // do something
      }
    • Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).

      Returns boolean | null

      true if the vertices are convex, false if not, null if not computable

    • Determines whether all coordinates of this rectangle are finite numbers.

      Returns boolean

      false if all coordinates are positive or negative Infinity or NaN; otherwise, true.

    • set new value to the Polygon

      Parameters

      • x: number

        position of the Polygon

      • y: number

        position of the Polygon

      • points: PolygonVertices | LineVertices

        array of vector or vertices defining the Polygon

      Returns Rect

      this instance for object chaining

    • Shifts the Polygon to the given position vector.

      Parameters

      • x: number

        The x coordinate or a vector point to shift to.

      • Optionaly: number

        The y coordinate. This parameter is required if the first parameter is a number.

      Returns void

      polygon.shift(10, 10);
      // or
      polygon.shift(myVector2d);
    • Shifts the Polygon to the given position vector.

      Parameters

      Returns void

      polygon.shift(10, 10);
      // or
      polygon.shift(myVector2d);