I am using pyBox2d and I have a problem with the speed of the simulation. I am trying to make a platformer-esque game and everything seems painfully slow. I am drawing with pygame, and running at a full 60 frames per second. However applying an impulse of 1000000000 does not seem to increase the speed of the object. Also, applying an impulse of (largenumber, 0), seems to negate gravity. (For example, if the character is in mid air, and "Left" is pressed, the character just slides leftward, but glides instead of falls)
Here is my code:
Code:
worldAABB=box2d.b2AABB()
worldAABB.lowerBound = (-10000, -10000)
worldAABB.upperBound = (10000, 10000)
world = box2d.b2World(worldAABB, (0,-900), True)
...
#def __init__(self, world, w, h, mass = 0, friction = 0, x=0, y=0):
main = display.Sprite(world, 50, 100, 1, 0, .1, 600)
ground = display.Sprite(world, 5000, 600, 0, 0, 0, 0)
...
while running:
...
if keys[pygame.K_LEFT]:
main.body.ApplyImpulse( (-1000000000,0),main.pos() )
if keys[pygame.K_RIGHT]:
main.body.ApplyImpulse( (1000000000,0),main.pos() )
if keys[pygame.K_UP]:
main.body.ApplyImpulse( (0,1000000000),main.pos() )
if keys[pygame.K_DOWN]:
main.body.ApplyImpulse( (0,-1000000000),main.pos() )
Sprite class:
Code:
class Sprite(object):
inertia = None
body = None
shape = None
sprite = None
mass = 0
size = (0,0)
static = False
color = (255,0,0)
surface_height = 0
def __init__(self, world, w, h, mass = 0, friction = 0, x=0, y=0):
bodyDef = box2d.b2BodyDef()
bodyDef.position = (x,y)
self.body = world.CreateBody(bodyDef)
shapeDef = box2d.b2PolygonDef()
shapeDef.SetAsBox(w/2.0, h/2.0)
shapeDef.density = float(mass) / (w*h)
shapeDef.friction = friction
self.shape = self.body.CreateShape(shapeDef)
self.body.SetMassFromShapes()