【问题标题】:Orthographic Camera screen on different sized phones不同尺寸手机上的正交相机屏幕
【发布时间】:2014-07-16 00:17:14
【问题描述】:

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

来自下面的评论:

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

【问题讨论】:

  • 您可以使用几种不同的策略来调整屏幕大小。像这样的固定纵横比并不是一个好的纵横比,因为它在没有完全相同比例的手机上看起来会失真。但是,无论您如何调整正交相机的尺寸,如果您正确计算触摸,您应该不会遇到问题。你用什么方法获取世界空间触摸位置?
  • 我正在使用 GestureDetector。这是我如何处理触摸的示例:@Override public boolean touchDown(float x, float y, int pointer, int button) { // TODO Auto-generated method stub xpos = x; return false; }

标签: java android camera libgdx orthographic


【解决方案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;       
}

【讨论】:

  • 完美运行!非常感谢
猜你喜欢
  • 2013-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多