Skip to content Skip to sidebar Skip to footer

Libgdx Touchinput Gives Strange Numbers For Position On The Screen

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 tryin

Solution 1:

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?

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

Vector3v3=newVector3(screenX, screenY, 0);
cam.unproject(v3);

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.

Solution 2:

A lot of people will use Vector3 for storing touch points and will use Gdx.input to get X and Y coordinates. Checkout Superjumper for more details, specifically the updateRunning function.

Post a Comment for "Libgdx Touchinput Gives Strange Numbers For Position On The Screen"