Game Development Reference
In-Depth Information
Note I could have used the flipper's shape names instead, but I wanted to hide
this implementation detail. No one but the Flipper class should be concerned
with what the flipper's frame and shape names are.
The attachFlipperAt method creates the revolute joints (see Listing 13-24 ) , with
a few modifications for the right flipper in order to change the direction and upper limit
of the right flipper's rotation. The point the flippers rotate around will be the anchor
point of their shapes, which is editable in PhysicsEditor.
Listing 13-24 . Creating the Flipper Revolute Joint
-(void) attachFlipperAt:(b2Vec2)pos
physicsBody- > SetTransform(pos, 0);
physicsBody- > SetType(b2_dynamicBody);
// turn on continuous collision detection to prevent tunneling
physicsBody- > SetBullet(true);
// create an invisible static body to attach to'
b2BodyDef bodyDef;
bodyDef.position = pos;
b2Body* staticBody = physicsBody- > GetWorld()- > CreateBody(&bodyDef);
// setup joint parameters
b2RevoluteJointDef jointDef;
jointDef.Initialize(staticBody, physicsBody, staticBody- > GetWorldCenter());
jointDef.lowerAngle = 0.0f;
jointDef.upperAngle = CC_DEGREES_TO_RADIANS(70);
jointDef.enableLimit = true;
jointDef.maxMotorTorque = 100.0f;
jointDef.motorSpeed = -40.0f;
jointDef.enableMotor = true;
if (type == kFlipperRight)
Search Nedrilad ::

Custom Search