Game Development Reference
In-Depth Information
The ImageRepresentationDelegate must specify a baseImageName , which is used in all of the use
cases of ImageRepresentation . If the ImageRepresentationDelegate implements only baseImageName :,
this indicates that a single image will be used for all instances of the actor. If a sequence of images
is to be used, the delegate object must implement the task getFrameCountForVariant:AndState :. If
a different sequence of images is to be used based on the state or variant of the actor, the delegate
must implement getNameForState : and getNameForVariant :, respectively. Technically speaking, if
just a single image is going to be used to represent all actors of a particular type, it is not required
to specify a delegate to an ImageRepresentation . However, the ImageRepresentation still requires
baseImageName to be specified.
Creating the Implementation of Powerup
The class Powerup must define how it is drawn, as well as its basic behavior. Because the class
Powerup will use a different sequence of images for each combination of state and variation, the
delegate for ImageRepresentation must implement all four of these tasks. For simplicity, we specified
that the class Powerup conforms to the protocol ImageRepresentationDelegate . Let's take a look at
the implementation of these methods in Listing 6-15.
Listing 6-15. Powerup.m (ImageRepresentationDelegate tasks)
-(NSString*)baseImageName{
return @"powerup";
}
-(int)getFrameCountForVariant:(int)aVariant AndState:(int)aState{
return 63;
}
-(NSString*)getNameForVariant:(int)aVariant{
if (aVariant == VARIATION_HEALTH){
return @"health";
} else if (aVariant == VARIATION_CASH){
return @"cash";
} else if (aVariant == VARIATION_DAMAGE){
return @"damage";
} else {
return nil;
}
}
-(NSString*)getNameForState:(int)aState{
if (aState == STATE_GLOW){
return @"glow";
} else if (aState == STATE_NO_GLOW){
return @"noglow";
} else {
return nil;
}
}
In this listing, we see the four tasks required by an ImageRepresentationDelegate to create an actor
represented by a different sequence of images for each combination of states and variations. The
task baseImageName returns the NSString "powerup" , indicating that all of the images for this actor
 
Search WWH ::




Custom Search