Game Development Reference
In-Depth Information
Listing 7-15. Example03Controller.m (tapGesture:)
- (void)tapGesture:(UIGestureRecognizer *)gestureRecognizer{
for (Asteroid* asteroid in [self actorsOfType:[Asteroid class]]){
[asteroid doHit:self];
}
}
In Listing 7-15, we see that the tapGesture: task, which is called when the user taps the screen,
simply iterates through each Asteroid in the scene and calls doHit: on it. It is because of this task
that we want to make sure we have easy access to the Asteroids in the scene.
The following section describes the implementation details of the actor Asteroid , as well the particle
Asteroid explodes.
Asteroid class and see how we can create a
Asteroid , let's take a
moment to understand the Asteroid class as whole. This will give us the context to understand the
particle effect while building another Actor class. The header for the Asteroid class is shown in
Listing 7-16.
Listing 7-16. Asteroid.h
@interface Asteroid : Actor{
}
@property (nonatomic) int level;
+(id)asteroid:(GameController*)aController;
+(id)asteroidOfLevel:(int)aLevel At:(CGPoint)aCenter;
-(void)doHit:(GameController*)controller;
@end
In Listing 7-16, we see the declaration of the class Asteroid . We see that Asteroid class extends
Actor and has two constructors. The constructor asteroid: is used by the Example03Controller to
add the biggest Asteroids into the scene. The constructor asteroidOfLevel:At: is used to create
and add the smaller Asteroids in the task doHit: , which is called after a tap event. Listing 7-17
shows the first constructors for the class Asteroid .
 
Search WWH ::




Custom Search