Using the accelerometer for steering

iOS applications also have another form of input: the accelerometer. This measures the orientation of the iOS device on the X, Y, and Z planes. Device orientation is a dynamic (if slightly delayed) input mechanism with a variety of uses. One of these uses is steering in racing video games.

Using the accelerometer for steering

Getting ready

Please refer to the project RecipeCollection01 for full working code of this recipe.

How to do it...

Execute the following code:

@implementation Ch2_AccelerometerSteering -(CCLayer*) runRecipe { //Enable the accelerometer and set its updateInterval self.isAccelerometerEnabled = YES; [[UIAccelerometer sharedAccelerometer] ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.