Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making a 2D scroller game where the player controls an airplane via the accelerometer I would like to know if it is possible to scale in and to scale out the sprite/airplane using the accelerometer z axis. I would like to know how to do this to create a depth illusion.

Any suggestion, tutorial recommendation, and comments are appreciated.


share|improve this question

Of course, you can access the Z data from the accelerometer just like you would access the X and Y data.

Sample cocos2d projects show how to use the accelerometer; in a nutshell, you will have a method as follows in the CCLayer subclass that controls your game:

- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
    NSLog(@"Accelerometer z value is %f\n", acceleration.z);

Keep in mind that the accelerometer only detects acceleration - it might be a bit tricky for you to achieve exactly the desired effect. For a depth effect graphics-wise, you might want to look into parallalax scrolling.

share|improve this answer
How would I use the parallax effect to do this trick? I mean I am using this effect for static objects such as the ground,rocks and such but I never thought of using it on a moving sprite. I am sorry I could not find a video to show you what I mean so to better explain myself just take your hand, face it towards you and just zoom it in and out the effect that you saw is the effect I would like to apply to my airplane using the accelerometer z axis however I don't know if this is possible. Thanks for responding. – user1068384 Jan 19 '12 at 0:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.