Java 方向始终导致纵向(libgdx中的运动控件)
我的代码如下:Java 方向始终导致纵向(libgdx中的运动控件),java,android,libgdx,orientation,Java,Android,Libgdx,Orientation,我的代码如下: Input.Orientation orientation = Gdx.input.getNativeOrientation(); message = ""; switch (orientation) { case Landscape: message += "Landscape\n"; break; case Portrait: message += "Portrait\n"; break;
Input.Orientation orientation = Gdx.input.getNativeOrientation();
message = "";
switch (orientation) {
case Landscape:
message += "Landscape\n";
break;
case Portrait:
message += "Portrait\n";
break;
default:
message += "Whatever\n";
}
上面的代码(内部渲染方法)始终指示设备处于纵向模式,即使我旋转设备!我做错了什么?如何准确地检测设备是处于纵向还是横向模式?getNativeOrientation()不会返回设备的当前方向,而是在正确按住屏幕时返回屏幕是横向还是纵向(在大多数手机上,它应该返回纵向,但我猜在平板电脑和HTC ChaCha等手机上,它返回横向) 有几种方法可以获得当前方向:
- 建议:使用
返回设备相对于其本机方向的旋转角度(0、90、180、270)。与Gdx.input.getRotation()
一起使用,您应该能够为所有设备获得正确的方向getNativeOrtation()
android:screenOrientation=“scape”
,此方法将始终返回scape
用法示例:
int rotation = Gdx.input.getRotation();
if((Gdx.input.getNativeOrientation() == Input.Orientation.Portrait && (rotation == 90 || rotation == 270)) || //First case, the normal phone
(Gdx.input.getNativeOrientation() == Input.Orientation.Landscape && (rotation == 0 || rotation == 180))) //Second case, the landscape device
Gdx.app.log("Orientation", "We are in landscape!");
else
Gdx.app.log("Orientation", "We are in portrait");
- 在本机端(Android)创建界面,并将其传递给游戏
- 如果您将此用作控件,可能应该使用或