b2PolygonShape Class
A convex polygon. It is assumed that the interior of the polygon is to the left of each edge.
Methods
fromEdge
v1x
v1y
v2x
v2y
Create edge shape. Edge shapes are line segments. These are provided to assist in making a free-form static environment. Edge shapes can collide with circles and polygons bodies but not with themselves. Edge bodies have no volume.
Parameters:
-
v1x
FloatX coordinate of the first point of the body from the centre of the shape. The positive values are in right and top directions.
-
v1y
FloatY coordinate of the first point of the body from the centre of the shape. The positive values are in right and top directions.
-
v2x
FloatX coordinate of the second point of the body from the centre of the shape. The positive values are in right and top directions.
-
v2y
FloatY coordinate of the second point of the body from the centre of the shape. The positive values are in right and top directions.
Returns:
Example:
var shape = b2PolygonShape.fromEdge(v1x, v1y, v2x, v2y);
var body = ...world.createBody(shape, #dynamic, 1 , 0.3, 0.03);
fromPoly
array
Create new polygon shape acording to the parameters.
Parameters:
-
array
ArrayArray of verticles. The array should contains objects with two values: x and y -> distance from center in pixels (positive values are located up and right). Points in array should by in CCW order. Minimum number of vertex are 3 maximum (ussally) 8.
Returns:
Example:
// This defines a triangle in CCW order.
var verticles = { var shape = new Array(
// top - left
{x : 0.0 y : 0.0},
// bottom - left
{x : 1.0, y : 0.0},
// bottom - right
{x : 0.0, y : 1.0}
)
// create a triangle body
var shape = b2PolygonShape.fromPoly(verticles);
var body = ...world.createBody(shape, #dynamic, 1 , 0.3, 0.03);
fromRect
width
height
[center]
[angle]
Create new rectangle shape acording to the parameters.
Parameters:
Returns:
Example:
// load image
var img = Bitmap.fromFile("app://img.png");
// create shape
var shape = b2PolygonShape.fromRect(img.width, img.height);
// create body
var body = this._world.createBody(shape, #dynamic, 1 , 0.3, 0.03);