問題描述
獲取實際觸摸位置 LibGDX (Get actual touch position LibGDX)
When using Gdx.input.getX()
or Gdx.input.getY()
the position seems to be fine on the computer but when I put it on an Android tablet the position is completely off.
I've done some research and saw somewhere that it was mentioned I should use camera.unproject(Vector3)
but I'm not sure if that's what I need to use or how to use it.
參考解法
方法 1:
class Pause extends Screen
{
Vector3 touchPoint;
Pause()
{
touchPoint = new Vector3();
}
void update(float deltaTime)
{
if(Gdx.input.justTouched())
{
cam.unproject(touchPoint.set(Gdx.input.getX(),Gdx.input.getY(), 0));
if(OverlapTester.pointInRectangle(Assets.resumeButton.getBoundingRectangle(), touchPoint.x,touchPoint.y))
{
some thing u want to do
}
}
(by Chris、Kumar Saurabh)