Search code examples
pythonbox2dtraceback

Box2D won't work with Python


I have installed Python 2.6.6 and Box2D 2.0.2b1. And can't create box2d world - b2World().

Simple example:

import Box2D
Box2D.b2World()

No matter what I type into function b2World, I received this error:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    Box2D.b2World()
  File "C:\Python26\lib\site-packages\Box2D\Box2D.py", line 4350, in __init__
    _Box2D.b2World_swiginit(self,_Box2D.new_b2World(*args))
TypeError: new_b2World expected 3 arguments, got 0

Solution

  • Try something like:

    world = b2World(gravity=(0,-10), doSleep=True)
    

    I had a look at the 2.0.2 version and it looks like you should pass your arguments like this:

    worldAABB=box2d.b2AABB()
    worldAABB.lowerBound = (-100.0, -100.0)
    worldAABB.upperBound = ( 100.0, 100.0)
    gravity = (0.0, -10.0)
    world = box2d.b2World(worldAABB, gravity, True)