LibGdx TOUCHINPUT给陌生号码在屏幕上的位置 [英] LibGdx TouchInput gives strange numbers for position on the screen

查看:151
本文介绍了LibGdx TOUCHINPUT给陌生号码在屏幕上的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个小问题。能不知道如何解决它。
我在我的LibGdx游戏中实现用户触摸输入。我的屏幕尺寸是下一:宽度= 408和高度= 272;
当我试图从法着陆打印值我东西,我得到绝对怪异号码在屏幕上的位置。他们可以比1000更大...
如何是它甚至有可能,如果我的屏幕尺寸是408x272?

have a small problem. Cannot understand how to solve it. I am implementing user touch input in my LibGdx game. My screenSize is next: width = 408 and height = 272; When I am trying to print values I get from method touchDown, I get absolutely weird numbers for positions on the screen. They can be even bigger than 1000... How is it even possible if my screenSize is 408x272?

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
System.out.println(screenX + "     " + screenY);    //For some reasons this gives completely absurd numbers for the positions on the screen.
return true;
}

这将是非常美联社preciated如果你能帮助我。我想我错过的东西容易和简单...谢谢你。

It will be very appreciated if you could help me. I think I miss something easy and straightforward... Thank you.

推荐答案

我能想到的唯一的事情是,你的屏幕大小是不是你想的是 - 你可能混合了与已经定义了你的相机,查看一个408x272的区域?是窗口的屏幕上的大小实际上408x272像素

The only thing I can think of is that you screen size is not what you think it is - are you possibly mixing that up with having defined your Camera to view a 408x272 region? Is the size of the window on the screen actually 408x272 pixels?

如果这是问题,你需要做的 - 假设你使用的是 OrthographicCamera

If this is the issue, you need to do - assuming you are using an OrthographicCamera:

Vector3 v3 = new Vector3(screenX, screenY, 0);
cam.unproject(v3);

这将设置 3.x版 v3.y 你在找什么。

This will set the v3.x and v3.y to what you are looking for.

如果这不是问题,我会尽量让怪位置如何与所预期的意义 - 它表现得像画面上是大?难道翻转?如果你成功地观察到,这可能是更容易弄清楚。

If this is not the issue, I'd try to make sense of how the strange positions are related to the expected ones - does it behave like the screen was larger? Is it flipped? If you manage to observe that, it might be easier to figure out.

这篇关于LibGdx TOUCHINPUT给陌生号码在屏幕上的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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