Chris
Chris

Reputation: 2465

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.

Upvotes: 5

Views: 6759

Answers (1)

Kumar Saurabh
Kumar Saurabh

Reputation: 2305

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
        }

}

Upvotes: 8

Related Questions