Friday, October 10, 2008

pybox2d r86 - Thin Line Segment Shapes

 


Thanks to shaktool, thin line segments are now available for Box2D! I've ported them to pybox2d, which you can see if you use svn r86. It's still in beta in the C++ form, so API changes can be expected.

This is great news for creating platformer games, and even terrain in general. No longer will you have to worry about tesselating non-convex shapes to get the slopes and such that you want. See the new testbed demos,
test_DynamicEdges.py
test_PyramidStaticEdges.py
test_StaticEdges.py

They are very simple to use, also:

(Assuming a b2Body, body, at the origin)
verts = [ (50.0,0.0), (-50.0,0.0) ]
edgeDef = box2d.b2EdgeChainDef()
edgeDef.setVertices(verts)
edgeDef.isALoop = False
body.CreateShape(edgeDef)

Creates a big, static line at the bottom of your world. If you want to make a dynamic one, simply use body.SetMassFromShapes() afterward. However, there are some problems with the dynamic versions (see the forum post)

1 comment: