elements documentation (r105) | Reference Index || Help Contents || Manual elements || elements.add || elements.callbacks || elements.world || Box2D

elements.add

elements subclass for adding bodies to the world

- elements.add.ball - add a circle shaped body
- elements.add.complexPoly - add a convex polygon
- elements.add.concavePoly - add a concave polygon
- elements.add.poly - add a already simplified polygon
- elements.add.rect - add a rectangle body
- elements.add.triangle - add a triangle body

The subclass can add a variety of bodies to the physic world. The lengths and positions the user supplies as parameters can either be meters or pixels, according to what you have set with elements.set_inputUnit. By default, the input is set to pixels, and box2d will crash if you supply them in the wrong unit.
[[comment elements.add]]
elements.add.ball

add a circle shaped body
`elements.add.ball(pos, radius, dynamic=True, density=1.0, restitution=0.16, friction=0.5)): return box2d.b2Body`
Add a dynamic ball at pos after correcting the positions and legths to the internal meter system if neccessary (if INPUT_PIXELS).
Parameters: pos (x, y) is the center of the circle, radius in either pixels or meters, according to the input unit system. See elements.set_inputUnit. The other, optional parameters set the physical behaviour and can be looked up here.
[[comment elements.add.ball]]

elements.add.complexPoly

make a reduced, convex polygon of the vertices and add as body with one shape.
`elements.add.complexPoly(vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5): return box2d.b2Body`
Parameters: vertices is a list with vertices of the polygon. This list will be reduced, a convex hull created and the body with one shape added to the world. The max. number of vertices after reducing is set in box2d/Source/Common/b2Settings.h
[[comment elements.add.complexPoly]]

elements.add.concavePoly

make a reduced, concave polygon out of the vertices
`elements.add.concavePoly(vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5): return ?`
Parameters: vertices is a list of points for the polygon. The algorithm will detect lines and add as many rectangles as needed to one body for the specified polygon vertices.
[[comment elements.add.concavePoly]]

elements.add.poly

add a already centered, reduced and convex polygon
`elements.add.poly(pos, vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5): return box2d.b2Body`
Parameters: pos (x,y) is the center of the polygon on the screen, either in pixels or meters (elements.set_inputUnit). the vertices have to be a convex hull with max box2d.b2_maxPolygonVertices vertices (8 by default).
[[comment elements.add.poly]]

elements.add.rect

add a rectangle to the world
`elements.add.rect(pos, width, height, dynamic=True, density=1.0, restitution=0.16, friction=0.5): return box2d.b2Body`
Parameter units according to the input system specified with elements.set_inputUnit (pixels or meters). pos (x,y) is the center of the rectangle.
[[comment elements.add.rect]]

elements.add.triangle

add a triangle to the world
`elements.add.triangle(pos, sidelength, dynamic=True, density=1.0, restitution=0.16, friction=0.5): return box2d.b2Body`
Parameters: pos (x,y) is the center of the triangle.
[[comment elements.add.triangle]]