class nape.shape.Polygon extends Shape
Available on all platforms
Polygon subtype of Shape.
*
* Can be used to simulate any convex polygon.
Class Fields
static function box(width:Float, height:Float, ?weak:Bool = false):Array<Vec2>
Construct a polygon representing an origin centred box.
*
* This method is equivalent to calling: Polygon.rect(-width/2,-height/2,width,height)
*
*
width | The width of the box (This value may be negative but will * make no difference). * |
height | The height of the box (This value may be negative but will * make no difference). * |
weak | If true, the generated list of vertices will be allocated as * weak Vec2s so that when this list is passed to a Nape function * these Vec2s will be automatically sent back to object pool. * (default false) * |
returns | An array of Vec2 representing the given box. |
static function rect(x:Float, y:Float, width:Float, height:Float, ?weak:Bool = false):Array<Vec2>
Construct a polygon representing a rectangle.
*
* For a dynamic object, you may consider use of the box method instead
* as dynamic bodies will only respond as expected if their centre of mass
* is equal to the origin.
*
* The generate polygon will have coordinates equal to:
*
* (x, y) -> (x + width, y + height) ** Negative values of width/height are permitted so that the given x/y values * may not necessarigly be the top-left corner of rectangle. * *
x | The x coordinate of rectangle. * |
y | The y coordinate of rectangle. * |
width | The width of the ractangle. This value may be negative. * |
height | The height of the rectangle This value may be negative. * |
weak | If true, the generated list of vertices will be allocated as * weak Vec2s so that when this list is passed to a Nape function * these Vec2s will be automatically sent back to object pool. * (default false) * |
returns | An array of Vec2 representing the given rectangle. |
static function regular(xRadius:Float, yRadius:Float, edgeCount:Int, ?angleOffset:Float = 0.0f, ?weak:Bool = false):Array<Vec2>
Construct a regular polygon centred at origin.
*
* Vertices are created at positions on the edge of an ellipsoid of given
* radii, when radii are not equal the vertices will not have an equal
* angle between them; it will be as though an actual regular polygon were
* created, and then squashed to conform to the input radii.
*
*
xRadius | The x radius of polygon before angleOffset rotation. * |
yRadius | The y radius of polygon before angleOffset rotation. * |
edgeCount | The number of edges/vertices in polygon. * |
angleOffset | The clockwise angular offset to generate vertices at * in radians. (default 0.0) * |
weak | If true, the generated list of vertices will be allocated as * weak Vec2s so that when this list is passed to a Nape function * these Vec2s will be automatically sent back to object pool. * (default false) * |
returns | An array of Vec2 representing the polygon. |
Instance Fields
var localVerts:Vec2List
Local coordinates of vertices.
*
* This list can be modified, but modifications to a Polygon that is
* part of a static Body inside of a Space will given an error in
* debug builds.
var worldVerts:Vec2List
World coordinates of vertices.
*
* This list can be accessed, but any queries of values will result
* in an error in debug builds unless this Polygon is part of a Body.
*
* This list is immutable.
function new(localVerts:Dynamic, ?material:Material = null, ?filter:InteractionFilter = null):Void
Construct a new Polygon.
*
* The localVerts parameter is typed Dynamic and may be one of:
* Array<Vec2>, flash.Vector<Vec2>, Vec2List, GeomPoly
*
*
localVerts | The local vertices of polygon. * |
material | The material for this polygon. (default new Material()) * |
filter | The interaction filter for this polygon. * (default new InteractionFilter()) * |
returns | The constructed Polygon. * |