Class: Polygon

Polygon

new gdjs.Polygon()

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

Members

centerArray

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

edgesArray

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

verticesArray

The vertices of the polygon

Methods

staticgdjs.Polygon.collisionTest(p1, p2, ignoreTouchingEdges){Object}

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

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

Name Type Description
p1 gdjs.Polygon

The first polygon

p2 gdjs.Polygon

The second polygon

ignoreTouchingEdges boolean | undefined

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

Returns:
Type Description
Object returnValue.collision is equal to true if polygons are overlapping

staticgdjs.Polygon.isPointInside(poly, x, y){boolean}

Check if a point is inside a polygon.

Uses PNPOLY by W. Randolph Franklin.

Name Type Description
poly gdjs.Polygon

The polygon to test

x number

The point x coordinate

y number

The point y coordinate

Returns:
Type Description
boolean true if the point is inside the polygon

staticgdjs.Polygon.raycastTest(poly, startX, startY, endX, endY)

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

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

Name Type Description
poly gdjs.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:
A raycast result with the contact points and distances