Game Development Reference
In-Depth Information
@interface Example01Controller : UIViewController {
CADisplayLink* displayLink;
Viper01* viper;
}
-(void)updateScene;
-(void)viewTapped:(UIGestureRecognizer*)aGestureRecognizer;
@end
We see in Listing 5-1 that the class extends UIViewController and has two fields. The first field is
called displayLink and is of type CADisplayLink that is imported from the QuartzCore framework.
The second field is called viper and is of type Viper01 . It is used to represent the spaceship. There
are also two tasks defined: the first is called updateScene and will be used to update the UIViews that
make up the scene. The second is called viewTapped , and it is used to manage user input. Let's take
a look at the Viper01 header file in Listing 5-2 and see how we are representing the spaceship.
Listing 5-2. Viper01.h
#import <Foundation/Foundation.h>
@interface Viper01 : UIImageView {
}
@property float speed;
@property CGPoint moveToPoint;
-(void)updateLocation;
@end
In Listing 5-2, we see that Viper01 extends UIImageView and has two properties. The speed property
describes how fast the viper will move, and the moveToPoint property keeps track of which point
on the screen the spaceship is moving. The task updateLocation does the work of incrementally
updating the location of the spaceship.
Implementing the Classes
Now that we have seen the definitions of the classes we will be using in this example, let's take a
look at the implementation, starting with the viewDidLoad task of Example01Controller class shown
in Listing 5-3.
Listing 5-3. Example01Controller.m (viewDidLoad)
- (void)viewDidLoad
{
[super viewDidLoad];
[self setTitle:@"Simple Movement"];
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(viewTapped:)];
[self.view addGestureRecognizer:tapRecognizer];
 
Search WWH ::




Custom Search