I want to move the ball as I move the device but I can not able to find how to use accelerometer in libGDX. I know that Gdx.input.getAccelerometerX() returns x coordinate but I don't know how to apply it to the body I have created.
|
|
|||||||||||
|
|
LibGDX offers these three methods in the
All three return a value in degrees. They tell you what angle the phone's being held at in the world, so you should also be able to construct a plane in your game which the ball would be sitting on, and thus determine how the ball should roll. Do note these only map perfectly to the screen if the phone is facing north, so you'd need to use the Azimuth value to find the direction of the game's local 'north' (which points towards the top or the side of the phone). From there you just implement the physics of a ball rolling down a hill, which would mean applying acceleration to the ball depending on the direction and steepness of the ramp it's on. |
|||||
|
|
I have found an answer of my question after hardworking towards it. The solution is cfg.useAccelerometer = true; For using accelerometer we have to enable it in the android file that this I was missing |
|||||
|


