Polygon

Polygon

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

Constructor

new Polygon()

Source:

Members

center

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

Source:

edges

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

Source:

vertices

The vertices of the polygon

Source:

Methods

(static) collisionTest(p1, p2, ignoreTouchingEdges)

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

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

Parameters:
Name Type Description
p1

The first polygon

p2

The second polygon

ignoreTouchingEdges

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

Returns:
Type Description

returnValue.collision is equal to true if polygons are overlapping

Source:

(static) isPointInside(poly, x, y)

Check if a point is inside a polygon.

Uses PNPOLY by W. Randolph Franklin.

Parameters:
Name Type Description
poly

The polygon to test

x

The point x coordinate

y

The point y coordinate

Returns:
Type Description

true if the point is inside the polygon

Source:

(static) 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.

Parameters:
Name Type Description
poly

The polygon to test

startX

The raycast start point X

startY

The raycast start point Y

endX

The raycast end point X

endY

The raycast end point Y

Returns:
Type Description

A raycast result with the contact points and distances

Source: