Left-click to create an object. Right-click to show next example.
Box2DJS is a JavaScript port of Box2D Physics Engine. To tell the truth, this is converted from Box2DFlashAS3_1.4.3.1 in an automatic manner. (The reason why not Box2DFlashAS3_2.0.0 based is simply because I overlooked the renewal.)
Because this libray does not have a lazy-loading system now, you should load all classes before starting your simulation. To make things worse, each library has a bit complecated dependency each other so that loading libraries in wrong order may cause a fatal error. To avoid such a trouble, it is strongly recomended to copy the header part of this file or `index.html' including the downloaded zip file.
Concerning the Box2D APIs of the library, they are completely same as Box2DFlashAS3. Please google information about it.
var worldAABB = new b2AABB(); worldAABB.minVertex.Set(-1000, -1000); worldAABB.maxVertex.Set(1000, 1000); var gravity = new b2Vec2(0, 300); var doSleep = true; var world = new b2World(worldAABB, gravity, doSleep);
var circleSd = new b2CircleDef(); circleSd.density = 1.0; circleSd.radius = 20; circleSd.restitution = 1.0; circleSd.friction = 0; var circleBd = new b2BodyDef(); circleBd.AddShape(circleSd); circleBd.position.Set(x,y); var circleBody = world.CreateBody(circleBd);
var jointDef = new b2RevoluteJointDef(); jointDef.anchorPoint.Set(250, 200); jointDef.body1 = world.GetGroundBody(); jointDef.body2 = circleBody; world.CreateJoint(jointDef);
world.Step();
If you have some requests or find any bugs, please tell me about them.