Android Accelerometer Issue

前端 未结 2 1984
野性不改
野性不改 2021-01-24 04:35

My game uses the accelerometer, everything works fine but I noticed there is going to be a slight issue with some phones. The game forces the orientation to be landscape however

相关标签:
2条回答
  • 2021-01-24 04:53

    Here a solution provided by NVidia to deal nicely with the device default orientation: https://stackoverflow.com/a/14313663/1489493

    0 讨论(0)
  • 2021-01-24 04:57
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();
    

    from http://developer.android.com/reference/android/view/Display.html:

    public int getRotation ()

    Returns the rotation of the screen from its "natural" orientation. The returned value may be Surface.ROTATION_0 (no rotation), Surface.ROTATION_90, Surface.ROTATION_180, or Surface.ROTATION_270. For example, if a device has a naturally tall screen, and the user has turned it on its side to go into a landscape orientation, the value returned here may be either Surface.ROTATION_90 or Surface.ROTATION_270 depending on the direction it was turned. The angle is the rotation of the drawn graphics on the screen, which is the opposite direction of the physical rotation of the device. For example, if the device is rotated 90 degrees counter-clockwise, to compensate rendering will be rotated by 90 degrees clockwise and thus the returned value here will be Surface.ROTATION_90.

    You'll have to experiment with the devices to make sure android knows the "natural" orientation correctly. If so, then just check for ROTATION_90 (or ROTATION_270) to see if the device is on it's side or not. If so, then switch x and y axis.

    0 讨论(0)
提交回复
热议问题