Game Development Reference
In-Depth Information
Figure 7-2.
Three saucers and a shield
The shield image is partially transparent and is designed be drawn over a saucer, as can be seen in
the scaled up saucer with the shield drawn over it.
To understand how all the parts and pieces of this example fit together, we will start by looking at the
implementation of the class
Example02Controller
, starting with the
doSetup
task, shown in Listing 7-1.
Listing 7-1. Example02Controller.m (doSetup)
-(BOOL)doSetup
{
if ([super doSetup]){
NSMutableArray* classes = [NSMutableArray new];
[classes addObject:[Saucer class]];
[classes addObject:[Bullet class]];
[self setSortedActorClasses:classes];
return YES;
}
return NO;
}
In Listing 7-1, we see the
doSetup
task of the class
Example02Controller
. This method simply
indicates that we want to keep actors of type
Saucer
and
Bullet
sorted for easy access later on. We
do this by creating an
NSMutableArray
called classes and adding the class objects for two classes in
which we are interested. The
NSMutableArray
classes are then passed to
setSortedActorClasses:
.
This way, when we call
actorsOfType:
in the future, we will not have to sort through all of the actors
to find them. Next, we want to take a look at the code that describes the action in this example that
is found in the task
updateScene
of class
Example02Controller.
See Listing 7-2.