Fork me on GitHub
View source

package haxepunk.masks

class Polygon


extends Hitbox

Uses a convex polygonal structure to check for collisions.

Static functions

View source

static createFromArray (points : Array<Float>) : Polygon

Creates a polygon from an array were even numbers are x and odd are y


Parameters:
points   

Array containing the polygon's points.


Returns:

The polygon

View source

static createPolygon (sides : Int = 3, radius : Float = 100, angle : Float = 0) : Polygon

Creates a regular polygon (edges of same length).


Parameters:
sides   

The number of sides in the polygon.

radius   

The distance that the vertices are at.

angle   

How much the polygon is rotated (in degrees).


Returns:

The polygon

View source

static fromPoints (points : Array<Vector2>, origin : Vector2) : Masklist

Creates a list of convex polygonal masks based on an array of vertices defined counter-clockwise. The polygon must be simple (non-self-intersecting), but not necessarily convex.


Parameters:
points   

An array of coordinates that define the polygon (must have at least 3 and defined counter-clockwise).

origin   

Pivot point for rotations.

Variables

angle : Float

Rotation angle (in degrees) of the polygon (rotates around origin point).

read only maxX : Int

Right x bounding box position.

read only maxY : Int

Bottom y bounding box position.

read only minX : Int

Left x bounding box position.

read only minY : Int

Top y bounding box position.

origin : Vector2

The polygon rotates around this point when the angle is set.

points : Array<Vector2>

The points representing the polygon.

If you need to set a point yourself instead of passing in a new Array you need to call update() to make sure the axes update as well.