不同大小的手机上的正交相机屏幕

时间:2014-07-16 00:17:14

标签: java android camera libgdx orthographic

我的正交相机初始化为540x960(我的HTC One屏幕的大小)。但是,当我在另一部带有更大屏幕的手机上试用它时,每当我点击移动我的纹理时,我都会触摸到触摸的位置和纹理移动到的位置。我应该使用不同的尺码技术吗?比如Gdx.graphics.getWidth()和.getHeight()的大小?

来自以下评论:

@Override         
public boolean touchDown(float x, float y, int pointer, int button) {
    xpos = x;       
    return false;       
}

1 个答案:

答案 0 :(得分:1)

您只能获得屏幕的x位置。要将其转换为世界空间(游戏的坐标系),您需要将其放入Vector3并从相机取消投影,如下所示:

@Override         
public boolean touchDown(float x, float y, int pointer, int button) {
    Vector3 touchPoint = new Vector3(x, y, 0); //0 is arbitrary since this is in 2D
    camera.unproject(touchPoint); //now touchPoint contains the world position of the touch
    xpos = touchPoint.x;      
    ypos = touchPoint.y; //if you need it. 
    return false;       
}
相关问题