![ccmenu add child cocos2dx ccmenu add child cocos2dx](http://cdn-ak.f.st-hatena.com/images/fotolife/h/hyoromo/20150224/20150224125105.jpg)
Eventually, once it is entirely horizontal, x is -1 and now y and z are 0. Now tilt it to the left a bit and x starts going negative, with y increasing as you aren’t tilting it straight down anymore. So if the phone is tilted so that it is sitting vertically, the y value would be -1, and x and z would be 0 or neutral.
![ccmenu add child cocos2dx ccmenu add child cocos2dx](https://m.gjcdn.net/game-screenshot/400/68323-dc8iev7m-v4.png)
In that way, as you tilt your phone, the x, y and z values will change depending on which direction the ball would try to roll. The wording might suggest that the acceleration implies movement, but instead think of it as how much tug there is on an invisible rubber ball at the center of the phone, based on gravity as well as movement. Timestamp – a precise time of when the acceleration event occurred
![ccmenu add child cocos2dx ccmenu add child cocos2dx](https://s3.envato.com/files/264399792/android/ss_android_3.jpg)
Z – acceleration along the z-axis or up and down Y – acceleration along the y-axis or top to bottom X – acceleration along the x-axis or side to side Then, when the accelerometer sends you a message, you will receive a UIAcceleration object which has four properties (assuming the device is lying flat on its back): What you need to do is calibrate the device to account for the level of tilt the player is comfortable with.įirst, if you have used the accelerometer (whether in cocos2D or elsewhere) you know that you provide a hook for the following method: -(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration Intuitively it seems obvious that there should be a way to allow for this, and as it turns out there is. You hear people explain they would like to be able to at least hold it at a slight angle and still have it be playable. If you have created a tilt-based game using the iOS accelerometer, one of the complaints you might have heard was about having to hold the device flat, face up, in order to keep the tilt centered.