Game Development Reference
In-Depth Information
In Figure 8-2 , we see 12 power-ups organized into three columns and four rows. The power-ups
start disabled, like the one in the lower right. When the user taps the screen, a power-up enables,
becoming brighter and spinning. The power-up that is enabled is based on the number of fingers
used in the gesture and whether one, two, or three fingers are used. For example, a two-finger triple
tap enabled the right-most power-up on the second row. Similarly, a three-finger single tap enabled
the left-most power-up on the third row. So, in short, the columns show the number of taps and
the rows the number fingers involved. If you want to waste an hour of your life, try to get all of the
power-ups spinning. I think I got it to happen, but I could not get a screenshot in time to prove it.
This demo is implemented in the class TapGestureController . Listing 8-8 shows the file
TapGestureController.h .
Listing 8-8. TapGestureController.h
<TemporaryBehaviorDelegate>{
NSMutableArray* powerups;
- (void)tapGesture:(UITapGestureRecognizer *)sender;
TapGestureController and that it extends GameController
TemporaryBehaviorDelegate . We also see that there is an NSMutableArray
powerups that is used to store the 12 power-ups in this example. In other examples, we have
relied on GameController to keep track of different types of actors by specifying classes that should
be sorted. In this example, we are using a separate NSMutableArray because we want to use the order
of the Powerup objects in powerups to keep track of the row and column. Lastly, we see the declaration
of the task tapGesture : that is called when a UITapGestureRecognizer recognizes a gesture. The
implementation of the setup code for TapGestureController is shown in Listing 8-9.
Listing 8-9. TapGestureController.m (doSetup)
-(BOOL)doSetup{
if ([super doSetup]){
[self setGameAreaSize:CGSizeMake(320, 480)];
powerups=[NSMutableArray new];
for (int tap=0;tap<=2;tap++){
for (int touch=0;touch<=3;touch++){
float x=320.0/6.0+tap*320.0/3;
float y=480.0/8.0+touch*480/4;
CGPoint center=CGPointMake(x, y);
Powerup* powerup=[Powerup powerup:self At:center];
[self addActor: powerup];
[powerups addObject:powerup];
}
}
 
Search WWH ::




Custom Search