【问题标题】:libgdx system origin not match on device and on emulatorlibgdx 系统来源在设备和模拟器上不匹配
【发布时间】:2013-12-17 08:56:16
【问题描述】:

我的模拟器上的 LibGDX 在左下角显示原点 (0,0),但我的设备在左上角。请帮忙!

我修改了两个屏幕的教程作为我的程序,并使用font.draw()在屏幕上绘制字体作为菜单。字体的绘制工作正常,但实现InputProcessortouchup + touchDown 事件在设备和模拟器上给出了不同的系统来源。

模拟器:Android 4.0.3 15 级

设备:三星 Galaxy Nexus,安卓 4.2.1。

我应该从 LibGDX 切换到 OpenGL ES 2 吗?

非常感谢!

最好的问候。

【问题讨论】:

标签: java android android-emulator libgdx


【解决方案1】:

InputProcessor 中的 touchup 和 touchdown 事件为您提供了您点击的实际像素,以及设备屏幕单位。从左上角开始。您应该始终unproject 触摸相机坐标。

  • 创建一个 Vector3:

    Vector3 touchPoint = new Vector3();
    
  • 使用您的相机取消投影:

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button){
        cam.unproject(touchPoint.set(screenX, screenY, 0));
    
  • 然后使用 touchPoint.x 和 touchPoint.y 作为你的触摸坐标。

【讨论】:

  • 没问题,如果它有效,你能接受它作为答案吗?谢谢:)
猜你喜欢
  • 1970-01-01
  • 2014-08-25
  • 2012-06-30
  • 2017-08-23
  • 1970-01-01
  • 1970-01-01
  • 2017-11-12
  • 2012-06-24
  • 1970-01-01
相关资源
最近更新 更多