Game Development Reference
In-Depth Information
#import "BodySprite.h"
#import "Box2D.h"
@interface Ball : BodySprite < CCTargetedTouchDelegate>
BOOL moveToFinger;
CGPoint fingerLocation;
+(id) ballWithWorld:(b2World*)world;
There's the usual static initializer ballWithWorld , which takes a b2World pointer
as input. Then you have the member variable moveToFinger , which determines
whether the ball should move toward the touch location, and the fingerLocation
CGPoint variable, which specifies the actual location of the finger. We can use those
to have a little fun with the ball as long as the pinball game doesn't yet have any other
interactive elements to move the ball. Take a look at the Ball initialization and
cleanup methods in Listing 13-9 .
Listing 13-9 . The init and cleanup Methodsof the Ball Class
#import "Ball.h"
@implementation Ball
-(id) initWithWorld:(b2World*)world
if ((self = [super initWithShape:@"ball" inWorld:world]))
// set the parameters
physicsBody- > SetType(b2_dynamicBody);
physicsBody- > SetAngularDamping(0.9f);
// set random starting point
[self setBallStartPosition];
// enable handling touches
[[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self
Search Nedrilad ::

Custom Search