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\$
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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Ok thanks. It works exactly like I wanted it. Very useful information! \$\endgroup\$ – Patrick Jean Apr 7 '14 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\$ – Vaughan Hilts Apr 7 '14 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.