Book Image

Mastering Cocos2d Game Development

By : Alex Ogorek
Book Image

Mastering Cocos2d Game Development

By: Alex Ogorek

Overview of this book

Table of Contents (15 chapters)
Mastering Cocos2d Game Development
About the Author
About the Reviewers

Setting gravity by tilting the device

When your user tilts the device, the device's accelerometer will pick up that information at even the slightest, most minute values. This is beneficial to those who wish to use the accelerometer (or tilting) within their game, especially with regards to moving the character or manipulating gravity, which is what we'll cover in this section.

Ever since iOS 5.0, UIAccelerometer has been replaced by the Core Motion framework data. Thankfully, it's no more complicated, so let's get started.


If you aren't a registered developer and can't use your actual device to test (and have been doing so on the simulator), note that it's not possible to test the accelerometer with the simulator unless the data can be sent to the simulator. Here's a link that might be useful in this situation:

However, even if you can't test the accelerometer on the simulator by default, it will still work as intended on anyone's device, so if you plan...