3
\$\begingroup\$

I'm using the InputHandler's touchdown method. It gives me my screenX and screenY. Is there a simple way to convert screenX and screenY to world coordinates? By my understanding, InputHandler returns the coordinates in relation to your screen.

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

Sure.

Take your camera matrix and unproject it (or invert it). This can be done in libgdx like so:

 Vector3 worldCoordinates = new Vector3(screenX, screenY, 0);
 camera.unproject(worldCoordinates);

The documenation can be found here.

\$\endgroup\$
2
  • \$\begingroup\$ Ok thanks. It works exactly like I wanted it. Very useful information! \$\endgroup\$ Commented Apr 7, 2014 at 4:37
  • \$\begingroup\$ @PatrickJean If this answered your question, please accept it on the left hand side so other users can see this in the future. \$\endgroup\$ Commented Apr 7, 2014 at 4:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .