I am working on a game in Android, where the playerโs movement (left, top, right, bottom) is calculated depending on the direction in which you tilt your device.
I also wanted to do this at the beginning of the game, it calculates the current slope, so if the player holds the phone in any position, he can still play the game.
Here is how I did it:
(at startup):
defaultAccelX = SceneManager.activity.getAccelX(); defaultAccelY = SceneManager.activity.getAccelY();
(and then with each update):
float modifiedAccelX = (SceneManager.activity.getAccelX() - defaultAccelX); float modifiedAccelY = (SceneManager.activity.getAccelY() - defaultAccelY);
Now it works if the player holds the phone at the bottom. But if I hold the phone upside down, the top and bottom change to the opposite, and the right does not work.
Does anyone know how I should work with him in any direction?
thanks
source share