0

When I click on the top left corner it gives me 0,0 but I want the opposite result. I want to have a 0,0 coordinate when I click on the bottom left corner.

Basically when I go down the y coordinate is higher and when I go up the y coordinate is lower.It only happens when I do Gdx.input.getY();

enter image description here

Kevin Bryan
  • 1,647
  • 2
  • 17
  • 33
  • See [this question, the solution appears to be to add a so-called Camera.](http://stackoverflow.com/questions/7708379/changing-the-coordinate-system-in-libgdx-java) Other than that you can always to ``newY = height - y`` – Antares42 May 25 '15 at 16:20
  • I am using an orthographic camera: camera=new OrthographicCamera(); camera.setToOrtho(false,widthmheight); when I render sprites it gives me the right coordinates. only when I click the screen and get the pointer y coordinate is in riversed – Kevin Bryan May 25 '15 at 16:23

2 Answers2

1

This is true for almost any computer language or function.

The reason for this goes back. In earlier computers Cathode Ray Tubes (CRTs) would "draw" the image with a cathode ray from the upper left corner to the lower right.

To ease the interface between the graphics card memory and the CRT, the memory was read from the beginning and the image was drawn from the top left (with the lowest memory address) to the lower right (with the highest memory address). The reason for this order likely originates from the writing style in countries where the computer was invented.

The tradition of computing from left to right and top to bottom persists today, thus the origin for the plane field in in the upper left corner.

Caleb Limb
  • 304
  • 1
  • 11
  • So what can I do to make in normal? cause when I render something the coordinates are completely normal. – Kevin Bryan May 25 '15 at 16:32
  • You _could_ add the screen height to your render function and subtract the `y` value. Why would you need to do this though? If you are going to be working with computers in the future I suggest getting used to it. It will be easier in the long run. – Caleb Limb May 25 '15 at 16:37
  • I need to detect if the user is clicking my sprites. – Kevin Bryan May 25 '15 at 17:02
  • The y value for the mouse is the same as the y value for rendering so you shouldn't have to do anything special. – Caleb Limb May 25 '15 at 17:07
  • I mean touching, it's for android.Then why it's reversed? – Kevin Bryan May 25 '15 at 17:12
  • Once you have a working touch listener, the x and y value or your touch location will be act the same as the x and y value of your component locations. It sounds like you need to refine your code for getting the touch location, here's an [article](http://www.vogella.com/tutorials/AndroidTouch/article.html) that might help explain your problem. – Caleb Limb May 25 '15 at 17:18
1

Use the Camera's unproject method, which takes a Vector3 holding screen coordinates and converts them to camera (or world) coordinates. Try something like:

camera.unproject(screenCoords.set(screenX, screenY, 0);

Note, this will modify screenCoords to hold world coordinates (in your case... flipping the y, and taking into account any translation of the camera).

nEx.Software
  • 6,474
  • 1
  • 23
  • 34