0

I am making a simple, tilt controlled game using UIKit. So far, when I tilt the device the character moves in the appropriate direction. What I want him to do is to change the direction he is facing when I tilt the device. For example, when I tilt it left, I want the character to face left. Is there a way to detect whether the device was tilted left or right? If so, could you point me in the right direction please. Thanks, Tate

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • 2
    Don't you already have enough information to make that determination? If you know what direction to move, you also know what direction to face. – Rex M May 30 '10 at 18:30

2 Answers2

0

In John Ray's book titled iOS5 Application Development in 24 Hours, chapter 18 illustrates using the CMotionManager to get accelerometer and gyroscope data. Check out the following URL. You can download the source code and load up Chapter 18's ColorTilt application. It contains examples of how to use the gyroscopic information to determine which direction the device was tilted.

http://www.informit.com/store/sams-teach-yourself-ios-5-application-development-in-9780672335761

MikeyE
  • 1,756
  • 1
  • 18
  • 37
0

If knowing the actual rotation is good enough for you. Then I would suggest to use an UIViewController and override - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation method

If you need more stuff then I would suggest to do a search about accelerometer

nacho4d
  • 43,720
  • 45
  • 157
  • 240
  • Accelerometer tutorial: http://www.switchonthecode.com/tutorials/iphone-tutorial-reading-the-accelerometer UIViewController reference: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/didRotateFromInterfaceOrientation: – nacho4d May 30 '10 at 18:35
  • I needed more of a tilt based control not a full orientation change but thanks for trying. -Tate – Tate Allen May 30 '10 at 20:54