3
\$\begingroup\$

I am developing a game with accelerometer controls. This works well on all the mobile phones I've tested it on. However, when testing on a tablet, the y and x axes are reversed, presumably because the device's default orientation is landscape.

How can I identify the default orientation of the device, to set my axes accordingly?

(I'm using Android SDK 1.5 - 1.7.)

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

I figured out the best way to do this is to check the screen size on the device and base a boolean conditional to device on which axis to use. This is tested and working great.

// Check the screen layout to determine if the device is a tablet.

public boolean isTablet(Context context) { boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4); boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE); return (xlarge || large); } 

// Changle Accelx or Accely input based on the above (Im using OpenGLES 1.1)

if (isTablet(glGame)) { world.update(deltaTime, game.getInput().getAccelX()); } if (!isTablet(glGame)) { world.update(deltaTime, game.getInput().getAccelY()); } 
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.