Game Development Reference
In-Depth Information
In Listing 5-20, we see a number of small changes. We have added two new properties: rotation
and needsImageUpdate . The rotation property does not refer to the rotation of the asteroid; the
rotation property will be used by the updated Viper03 class to indicate what direction it is facing.
The property needsImageUpdated is a property that indicates that a new UIImage used should be used
for this actor. By setting this value to YES , we cause each asteroid to ask for a new image while it is
being animated. Let's take a look at the changes in the Asteroid03 class that take advantage of this
property—see Listing 5-21.
Listing 5-21. Asteroid03.h and Asteroid03.m (partial)
//From Asteroid.h
#define NUMBER_OF_IMAGES 31
return [[imageVariant stringByAppendingString:@"_"]
if ([controller stepNumber]%2 == 0){
self.imageNumber = imageNumber+1;
if (self.imageNumber > NUMBER_OF_IMAGES) {
self.imageNumber = 1;
}
self.needsImageUpdated = YES;
} else {
self.needsImageUpdated = NO;
}
CGPoint newCenter = self.center;
newCenter.y += self.speed;
self.center = newCenter;
if (newCenter.y - self.radius > controller.gameAreaSize.height){
[controller removeActor: self];
}
}
In Listing 5-12, we added two new properties to the asteroid class: imageNumber and imageVariant .
The property imageNumber keeps track of the current image that should be displayed. Like the
previous example, there are three types of asteroids: A, B, and C. The property imageVariant records
which one of these sequences of images should be used.
In Listing 5-12, we can see that we added a new task called imageName . This task overrides the
synthetic task as defined by Actor03 . In this way, we alter the name of the image that is returned.
We take the imageVariant and append the image number to it, creating a string that is of the form
Asteroid_B_0004 ” if the asteroid is of the B variety and if imageNumber is equal to 4.
Search WWH ::




Custom Search