Box2Dweb very slow on node.js
Posted
by
Peteris
on Game Development
See other posts from Game Development
or by Peteris
Published on 2012-03-30T08:46:47Z
Indexed on
2012/03/30
11:42 UTC
Read the original article
Hit count: 226
I'm using Box2Dweb on node.js. I have a rotated box object that I apply an impulse to move around. The timestep is set at 50ms, however, it bumps up to 100ms and even 200ms as soon as I add any more edges or boxes. Here are the edges I would like to use as bounds around the playing area:
// Computing the corners
var upLeft = new b2Vec2(0, 0),
lowLeft = new b2Vec2(0, height),
lowRight = new b2Vec2(width, height),
upRight = new b2Vec2(width, 0)
// Edges bounding the visible game area
var edgeFixDef = new b2FixtureDef
edgeFixDef.friction = 0.5
edgeFixDef.restitution = 0.2
edgeFixDef.shape = new b2PolygonShape
var edgeBodyDef = new b2BodyDef;
edgeBodyDef.type = b2Body.b2_staticBody
edgeFixDef.shape.SetAsEdge(upLeft, lowLeft)
world.CreateBody(edgeBodyDef).CreateFixture(edgeFixDef)
edgeFixDef.shape.SetAsEdge(lowLeft, lowRight)
world.CreateBody(edgeBodyDef).CreateFixture(edgeFixDef)
edgeFixDef.shape.SetAsEdge(lowRight, upRight)
world.CreateBody(edgeBodyDef).CreateFixture(edgeFixDef)
edgeFixDef.shape.SetAsEdge(upRight, upLeft)
world.CreateBody(edgeBodyDef).CreateFixture(edgeFixDef)
Can box2d really become this slow for even two bodies or is there some pitfall? It would be very surprising given all the demos which successfully use tens of objects.
© Game Development or respective owner