Options
All
  • Public
  • Public/Protected
  • All
Menu

Polygon represents a polygon which can be used to create collisions masks for RuntimeObject.

Hierarchy

  • Polygon

Index

Properties

center: FloatPoint = ...

The center of the polygon. This property is only valid after calling computeCenter, and remains valid until vertices are modified.

edges: FloatPoint[] = []

The edges of the polygon. This property is only valid after calling computeEdges, and remains valid until vertices are modified.

makeNewCollisionTestResult: () => CollisionTestResult = makeNewCollisionTestResult

Type declaration

makeNewRaycastTestResult: () => RaycastTestResult = makeNewRaycastTestResult

Type declaration

vertices: FloatPoint[] = []

The vertices of the polygon

Methods

  • Do a collision test between two polygons. Please note that polygons must convexes!

    You can read the result but do not keep a reference to it as it's a static object reused between function calls. If you need to keep the results, use copyCollisionTestResult.

    Uses Separating Axis Theorem .
    Based on this and this article.

    Parameters

    • p1: Polygon

      The first polygon

    • p2: Polygon

      The second polygon

    • ignoreTouchingEdges: boolean

      If true, then edges that are touching each other, without the polygons actually overlapping, won't be considered in collision.

    Returns CollisionTestResult

    A collision result. collision property is equal to true if polygons are overlapping. Do NOT keep a reference to this.

  • computeCenter(): FloatPoint
  • Returns FloatPoint

  • computeEdges(): void
  • Returns void

  • Copy a CollisionTestResult into another one. Use gdjs.Polygon.makeNewCollisionTestResult() to build a new destination before copying the existing source inside it.

    Parameters

    Returns void

  • Copy a RaycastTestResult into another one. Use gdjs.Polygon.makeNewRaycastTestResult() to build a new destination before copying the existing source inside it.

    Parameters

    Returns void

  • createRectangle(width: number, height: number): Polygon
  • Parameters

    • width: number
    • height: number

    Returns Polygon

  • crossProduct(a: FloatPoint, b: FloatPoint): number
  • Parameters

    • a: FloatPoint
    • b: FloatPoint

    Returns number

  • distance(minA: number, maxA: number, minB: number, maxB: number): number
  • Parameters

    • minA: number
    • maxA: number
    • minB: number
    • maxB: number

    Returns number

  • dotProduct(a: FloatPoint, b: FloatPoint): number
  • Parameters

    • a: FloatPoint
    • b: FloatPoint

    Returns number

  • isConvex(): boolean
  • Returns boolean

  • isPointInside(poly: Polygon, x: number, y: number): boolean
  • Check if a point is inside a polygon.

    Uses PNPOLY by W. Randolph Franklin.

    Parameters

    • poly: Polygon

      The polygon to test

    • x: number

      The point x coordinate

    • y: number

      The point y coordinate

    Returns boolean

    true if the point is inside the polygon

  • move(x: number, y: number): void
  • Parameters

    • x: number
    • y: number

    Returns void

  • normalise(v: FloatPoint): void
  • Parameters

    • v: FloatPoint

    Returns void

  • project(axis: FloatPoint, p: Polygon, result: FloatPoint): void
  • Parameters

    • axis: FloatPoint
    • p: Polygon
    • result: FloatPoint

    Returns void

  • Do a raycast test. Please note that the polygon must be convex!

    You can read the result but do not keep a reference to it as it's a static object reused between function calls. If you need to keep the results, use copyRaycastTestResult.

    For some theory, check Find the Intersection Point of Two Line Segments.

    Parameters

    • poly: Polygon

      The polygon to test

    • startX: number

      The raycast start point X

    • startY: number

      The raycast start point Y

    • endX: number

      The raycast end point X

    • endY: number

      The raycast end point Y

    Returns RaycastTestResult

    A raycast result with the contact points and distances. Do NOT keep a reference to this.

  • rotate(angle: number): void
  • Parameters

    • angle: number

    Returns void

Constructors

Generated using TypeDoc