Game Development Reference
In-Depth Information
try them in the PhysicsBox2D01 project. In this case, working code can explain it bet-
ter than words or a static image could. The fourth body is a static body to which one of
the dynamic bodies is also attached using a revolute joint.
For clarity and brevity I've extracted the code that creates the PhysicsSprite into
the createPhysicsSpriteAt method, and the createBodyFixture method
takes care of creating the body's shape and fixture.
-(void) addSomeJointedBodies:(CGPoint)pos
// Create a body definition and set it to be a dynamic body
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position = [self toMeters:pos];
bodyDef.position = bodyDef.position + b2Vec2(−1, -1);
b2Body* bodyA = world-> CreateBody(&bodyDef);
[self createBodyFixture:bodyA];
PhysicsSprite* spriteA = [self createPhysicsSpriteAt:pos];
[spriteA setPhysicsBody:bodyA];
bodyA-> SetUserData((__bridge void*)spriteA);
bodyDef.position = [self toMeters:pos];
b2Body* bodyB = world-> CreateBody(&bodyDef);
[self createBodyFixture:bodyB];
PhysicsSprite* spriteB = [self createPhysicsSpriteAt:pos];
[spriteB setPhysicsBody:bodyB];
bodyB-> SetUserData((__bridge void*)spriteB);
bodyDef.position = [self toMeters:pos];
bodyDef.position = bodyDef.position + b2Vec2(1, 1);
b2Body* bodyC = world-> CreateBody(&bodyDef);
[self createBodyFixture:bodyC];
PhysicsSprite* spriteC = [self createPhysicsSpriteAt:pos];
[spriteC setPhysicsBody:bodyC];
bodyC-> SetUserData((__bridge void*)spriteC);
b2RevoluteJointDef jointDef;
Search Nedrilad ::

Custom Search