Game Development Reference
In-Depth Information
will start with “
powerup
”. The task
getFrameCountForVariant:AndState
: simply returns 63, because
there are 63 images for each combination of state and variation. Other types of actors may wish to
have a different number of images for each combination of state and variation and are free to return
different numbers in
getFrameCountForVariant:AndState
:.
The tasks
getNameForVariant
: and
getNameForState
: return string representations for each variation
and state that apply to power-ups and allow
ImageRepresentation
to figure out exactly what image
should be used at a given time.
Finding the Correct Image for an Actor
Let's take a look at
ImageRepresentation's
task
getImageNameForActor
: so you can understand
ImageRepresentationDelegate
are used to identify an image name. See
ImageRepresentation.m (getImageNameForActor:)
NSString* imageName = baseImageName;
if (imageName == nil){
imageName = [delegate baseImageName];
}
NSString* variant = nil;
if ([delegate respondsToSelector:@selector(getNameForVariant:)]){
variant = [delegate getNameForVariant:[actor variant]];
}
NSString* state = nil;
if ([delegate respondsToSelector:@selector(getNameForState:)]){
state = [delegate getNameForState:[actor state]];
}
int frameCount = 0;
if ([delegate respondsToSelector:@selector(getFrameCountForVariant:AndState:)]){
frameCount = [delegate getFrameCountForVariant:[actor variant] AndState:[actor state]];
}
if (variant != nil){
imageName = [[imageName stringByAppendingString:@"_"] stringByAppendingString:variant];
}
if (state != nil){
imageName = [[imageName stringByAppendingString:@"_"] stringByAppendingString:state];
}
if (frameCount != 0){
imageName = [[imageName stringByAppendingString:@"_"] stringByAppendingString:[NSString
stringWithFormat:@"%04d", currentFrame] ];
}
return imageName;
}