Game Development Reference
In-Depth Information
{
kFlipperLeft,
kFlipperRight,
} EFlipperType;
@interface Flipper : BodySprite < CCTargetedTouchDelegate>
{
EFlipperType type;
b2RevoluteJoint* joint;
float totalTime;
}
+(id) flipperWithWorld:(b2World*)world flipperType:(EFlipperType)flipperType;
@end
Each flipper is anchored using a b2RevoluteJoint . Take a look at the flipper
initWithWorld method in Listing 13-23 to see how the flippers are created.
Listing 13-23 . Creating a Flipper
-(id) initWithWorld:(b2World*)world flipperType:(EFlipperType)flipperType
{
NSString* name = (flipperType == kFlipperLeft) ? @"flipper-left" : @"flipper-right";
self = [super initWithShape:name inWorld:world];
if (self)
{
type = flipperType;
// set the position depending on the left or right side
CGPoint flipperPos = (type == kFlipperRight) ? ccp(210, 65) : ccp(90, 65);
// attach the flipper to a static body with a revolute joint
[self attachFlipperAt:[Helper toMeters:flipperPos]];
// receive touch events
[[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self
priority:0
 
 
Search Nedrilad ::




Custom Search