O'Reilly logo

Learning Objective-C by Developing iPhone Games by Amy M. Booker, Joseph D. Walters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating and controlling the player

For a game like this, I thought it would be more fun to set it up with the accelerometer for the controller and have a touch to fire. As we want to use the accelerometer, we will need to add the CoreMotion to our header file and the motion manager property.

#import <AVFoundation/AVFoundation.h> 
@property CMMotionManager *mManager;

We will add our motion manager to our file similar to the way we talked about it in the previous chapter. For now, we just want to initialize it, start the updates, and make sure it is available:

//add an accelerometer for moving the player self.mManager = [[CMMotionManager alloc] init]; if (self.mManager.accelerometerAvailable) { [self.mManager startAccelerometerUpdates]; } else { NSLog(@"No ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required