Game Development Reference
In-Depth Information
CADisplayLink* displayLink;
//Managing Actors
NSMutableArray* actors;
NSMutableDictionary* actorViews;
NSMutableArray* toBeRemoved;
//Game Logic
Viper02* viper;
long stepNumber;
}
@property (nonatomic) CGSize gameAreaSize;
UIView actorView and that it is an IBoutlet wired up from the XIB file
5-9 . At the bottom of the file, we see the task sliderValueChanged: , which is called
when the slider from Figure 5-9 is moved. We also see the familiar displayLink object of type
CADisplayLink that will be used to configure redrawing the screen. The NSMutableArray actors is
used to store all current actors in the game, which are added and removed with the tasks addActor:.
The NSMutableArray toBeRemoved is used to hold actors that are marked to be removed with the
task removeActor: . The task doRemove is called at the end each call to updateScene to do the actual
removal of each actor. The NSMutableDictionary actorViews is used to map each actor to each
UIImageView that represents it. The variable viper of type Viper02 is a references to our spaceship,
and the last variable, stepNumber , keeps track of how many frames of the game we have stepped
through. Like most UIViewController classes, understanding how it works starts by looking at the
viewDidLoad task shown in Listing 5-14.
Listing 5-14. Example02Controller.m (viewDidLoad)
- (void)viewDidLoad
{
[super viewDidLoad];
[self setGameAreaSize:CGSizeMake(160, 240)];
actors = [NSMutableArray new];
actorViews = [NSMutableDictionary new];
toBeRemoved = [NSMutableArray new];
Actor02* background = [[Actor02 alloc] initAt:CGPointMake(80, 120) WithRadius:120
AndImage:@"star_field_iphone"];
[self addActor: background];
Search WWH ::




Custom Search