同时允许景观选项和加速度计,libgdx [英] Allowing both landscape options and accelerometer with libgdx

查看:193
本文介绍了同时允许景观选项和加速度计,libgdx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了libgdx的 SimpleApp教程。我已经改变了控制对游戏中使用的加速​​度计的,而不是触摸输入,以下列方式:

I've completed the SimpleApp tutorial for libgdx. I have changed the controls for the game to use the accelerometer instead of touch input, in the following way:


  • 在MainActivity.java

  • In MainActivity.java

cfg.useAccelerometer = true;


  • 在DropGame.java

  • In DropGame.java

    float acc = Gdx.input.getAccelerometerY();
    bucket.x += acc * 120 * Gdx.graphics.getDeltaTime();
    


  • 我的问题是,如何让双方的风景?我希望能够到我的设备把从一个横向180度,另外,并且有游戏转动它。

    My question is, how do I allow both landscapes? I would like to be able to turn my device 180 degrees from one landscape orientation to the other, and have the game rotate with it.

    我已经得到了我想要的,是设置 Android的最接近:screenOrientation =sensorLandscape在清单中,但同时它并没有使纵向旋转屏幕模式以外,还反转加速计控制

    The closest I've gotten to what I want, is setting android:screenOrientation="sensorLandscape" in the manifest, but while it does rotate the screen without allowing portrait mode, it also inverts the accelerometer controls.

    我是新来的Andr​​oid和libgdx,所以我可能会错过一些东西明显。

    I'm new to Android and libgdx, so I might have missed something obvious.

    在此先感谢!

    推荐答案

    Libgdx加速度维基(特别本节),加速度计数据的总是的相对于纵向。

    From the Libgdx accelerometer wiki (specifically this section), the accelerometer data is always relative to portrait orientation.

    您预计将使用的结果,<一个href=\"http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Input.html#getNativeOrientation--\"相对=nofollow> Gdx.input.getNativeOrientation() 或的 Gdx.input.getRotation(),并在必要时翻转的结果。

    You are expected to use the result of Gdx.input.getNativeOrientation() or Gdx.input.getRotation() and flip the results as necessary.

    维基和javadoc的是相对于本土的方向有点不一致,但它看起来像<一个href=\"https://github.com/libgdx/libgdx/blob/master/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInput.java#L803\"相对=nofollow>在code 确实维基说的话(波泰特始终是默认的方向,甚至在平板电脑上的Andr​​oid何处默认为横向)。

    The wiki and the javadoc are a bit inconsistent with respect to "native" orientations, but it does look like the code does what the wiki says ("portait" is always the default orientation, even on tablets where Android defaults to landscape).

    这篇关于同时允许景观选项和加速度计,libgdx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆