Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.)

share|improve this question
    
Looks like a duplicate of stackoverflow.com/questions/4553650/… –  Adam Apr 13 at 15:42

1 Answer 1

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());
}
share|improve this answer

Your Answer

 
discard

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.