Game Development Reference
In-Depth Information
jointDef.Initialize(bodyA, bodyB, bodyB-> GetWorldCenter());
bodyA-> GetWorld()-> CreateJoint(&jointDef);
jointDef.Initialize(bodyB, bodyC, bodyC-> GetWorldCenter());
bodyA-> GetWorld()-> CreateJoint(&jointDef);
// create an invisible static body to attach to
bodyDef.type = b2_staticBody;
bodyDef.position = [self toMeters:pos];
b2Body* staticBody = world-> CreateBody(&bodyDef);
jointDef.Initialize(staticBody, bodyA, bodyA-> GetWorldCenter());
bodyA-> GetWorld()-> CreateJoint(&jointDef);
b2BodyDef is reused for all bodies; only the position is modified for each body, and a
PhysicsSprite is created and assigned as user data to the body.
b2RevoluteJointDef is filled with data by using the Initialize method,
providing two bodies to connect to each other and a coordinate where the joint is loc-
ated. By using one body's GetWorldCenter coordinate, that body will be centered
on the joint and allowed only to rotate around itself.
The joint is created by the CreateJoint method of the b2World class. Even
though the HelloWorldLayer class in the PhysicsBox2D01 project has a
b2World member variable, I wanted to illustrate that you can also get the world
through any body—it doesn't matter which one—with the body's GetWorld method.
This is good to know, because in the ContactListener discussed earlier, you don't
have a b2World member variable, so you'll have to get the b2World pointer through
one of the contact bodies.
The Chipmunk physics engine was developed by Scott Lembcke of Howling Moon
Software. Chipmunk was actually inspired by an early version of Box2D, before it be-
came a full-fledged physics engine. More information about Chipmunk and its docu-
mentation are found on Scott's home page at .
Search Nedrilad ::

Custom Search