在Android设备上着落时获得正确的坐标
问题描述:
我正在编程LIBGX中的一个按钮。它适用于台式机好,但是当我启动它在Android上,我有一个不同的地方接触(使用真正的Android设备,而不是一个AVD林)来触发它下面是描述它一峰:在Android设备上着落时获得正确的坐标
下面的TouchDown代码:
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean touchDown (int x, int y, int pointer, int button) {
// your touch down code here
Vector3 coords = new Vector3(x, y, 0);
camara.unproject(coords);
if(coords.x >= 52 && coords.x<=129 && coords.y >= 158 && coords.y<=253){
shoot(1);
}
return true; // return true to indicate the event was handled
}
});
我有同样的问题没有的Vector3,我开始使用它,因为它是劝,但没有太多解决。下面是摄像头的声明:
camara = new OrthographicCamera();
camara.setToOrtho(false, 800, 480);
我做了一些调查,但无法找到合适的解决方案,我发现相机(ortographic,现实世界中,等)十分混乱。我会继续挖掘,这需要数小时,并且必须提出问题。我希望有人能指出我正确的方向。
答
请注意,Android屏幕中的原产地(0,0)
位于左上角屏幕的一角。因此,当您将值添加到y axis
时,对象将会向底部移动,当减去值时对象会向上移动。
在Android设备:
Origin
|
V
*-------------------------------
| ----> X axis |
| | |
| | |
| V Y-axis |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
-------------------------------
在台式机:
--------------------------------------------------------------
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|^Y axis |
| | |
| | |
| ----> X axis |
*-------------------------------------------------------------
^
|
Origin
可能的历史:
当电视机被用作显示屏的屏幕空间计算开始。电视的光栅枪也开始于左上角角落,所以这被认为是原点。
有关进一步的参考,你可以参考here
不知道我是否可以直接帮你,但我可以告诉你,x和y在Android坐标相比,计算机有所反转。 x和y坐标从左上角开始,而不是在其他操作系统上的左下角开始。请参阅:http://*.com/questions/11483345/how-android-screen-coordinates-works更多解释(抱歉,找不到任何直接从文档中找到的东西)。 – Darwind 2014-08-28 19:26:47
@Darwind谢谢非常,我会看看,谢谢你的评论 – dasjkdj 2014-08-28 19:27:26