Optional
x: number = 0origin point of the Polygon
Optional
y: number = 0origin point of the Polygon
array of vector defining the Polygon
The edges here are the direction of the n
th edge of the polygon, relative to
the n
th point. If you want to draw a given edge from the edge value, you must
first translate to the position of the starting point.
a list of indices for all vertices composing this polygon
Array of points defining the Polygon
Note: If you manually change points
, you must call recalc
afterwards so that the changes get applied correctly.
origin point of the Polygon
the shape type (used internally)
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)
x coordinate or a vector point to check
Optional
y: numbery coordinate
True if the polygon contain the point, otherwise false
Scales the polygon by the given factors along the x and y axes.
The factor by which to scale the polygon along the x-axis.
Optional
y: number = xThe factor by which to scale the polygon along the y-axis. Defaults to the value of x.
Reference to this object for method chaining
set new value to the Polygon
position of the Polygon
position of the Polygon
array of vector or vertice defining the Polygon
this instance for objecf chaining
set the vertices defining this Polygon
array of vector or vertice defining the Polygon
this instance for objecf chaining
Shifts the Polygon to the given position vector.
The x coordinate or a vector point to shift to.
Optional
y: numberThe y coordinate. This parameter is required if the first parameter is a number.
Translates the Polygon by the specified offset.
The x offset or a vector point to translate by.
Optional
y: numberThe y offset. This parameter is required if the first parameter is a number.
Reference to this object for method chaining
a polygon Object.
Please do note that melonJS implements a simple Axis-Aligned Boxes collision algorithm, which requires all polygons used for collision to be convex with all vertices defined with clockwise winding. A polygon is convex when all line segments connecting two points in the interior do not cross any edge of the polygon (which means that all angles are less than 180 degrees), as described here below :
A polygon's `winding` is clockwise if its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.