Game Development Reference
In-Depth Information
if ((self = [super initWithShape:@"plunger" inWorld:world]))
{
CGSize screenSize = [CCDirector sharedDirector].winSize;
CGPoint plungerPos = CGPointMake(screenSize.width - 13, -32);
physicsBody- > SetTransform([Helper toMeters:plungerPos], 0);
physicsBody- > SetType(b2_dynamicBody);
[self attachPlunger];
}
return self;
}
+(id) plungerWithWorld:(b2World*)world
{
return [[self alloc] initWithWorld:world];
}
Most interesting is the call to attachPlunger and the actual creation of the pris-
matic joint in this method, shown in Listing 13-16 .
Listing 13-16 . Creating the Plunger's Prismatic Joint
-(void) attachPlunger
{
// create an invisible static body to attach joint to
b2BodyDef bodyDef;
bodyDef.position = physicsBody- > GetWorldCenter();
b2Body* staticBody = physicsBody- > GetWorld()- > CreateBody(&bodyDef);
// Create a prismatic joint to make plunger go up/down
b2PrismaticJointDef jointDef;
b2Vec2 worldAxis(0.0f, 1.0f);
jointDef.Initialize(staticBody, physicsBody, physicsBody- > GetWorldCenter(),←
worldAxis);
jointDef.lowerTranslation = 0.0f;
jointDef.upperTranslation = 0.35f;
jointDef.enableLimit = true;
jointDef.maxMotorForce = 80.0f;
 
 
Search Nedrilad ::




Custom Search