Game Development Reference
In-Depth Information
To actually make the ball appear on the pinball table, you also have to add it to the
scene. Do that in the init method of the TableSetup class by adding these lines
below the initialization of the TablePart objects:
#import "TableSetup.h"
#import "Constants.h"
#import "TablePart.h"
#import "Ball.h"
@implementation TableSetup
-(id) initTableWithWorld:(b2World*)world
if ((self = [super initWithFile:@"pinball.pvr.ccz" capacity:5]))
. . .
Ball* ball = [Ball ballWithWorld:world];
[self addChild:ball z:-1];
return self;
If you ran the game now, you'd see the ball in the lower left-hand corner drop to the
ground, and that's it. You don't have any way to move it yet, so you need to add some
simple ball movement code for testing the bumpers before you get to add the plunger.
Forcing the Ball to Move
So far, the ball is just dropping down, and that's it. You need a way, at least temporary,
to control the ball. The Ball class implements the CCTargetedTouchDelegate
and has registered itself to receive touches. Let's check what the touch delegate meth-
ods do:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
moveToFinger = YES;
fingerLocation = [Helper locationFromTouch:touch];
return YES;
Search Nedrilad ::

Custom Search