0

How to invert Y axis? When I touch on bottom or top of the screen, the Y value is opposite I want

2 Answers2

0

You can't invert an axis per se. You see, in computer graphics, the 2D coordinate system is a bit different from the canonical one taught at school in maths. The difference is that in computer graphics the y-axis is in the opposite direction, that is, from the origin to the bottom it has positive values and from the origin to the top it has negative values. Also, the origin is at the top left corner of the screen. If you can't get used to it then you can always take the opposite value to what you get, for this, asume ycoord holds the value obtained then you can do ycoord = -ycoord and that will get you the value as you're used to. Also, if you want the origin to be in the bottom left corner then you should check your y-coordinate, if it's positive then substract the vertical resolution to it, and if it's negative then add the vertical resolution to it. But keep mind that you're going against the standard definition for coordinate systems in computer graphics.

Javier Silva Ortíz
  • 2,864
  • 1
  • 12
  • 21
0

I would say this is a duplicate questions of this one:

Move a shape to place where my finger is touched

Check on my answer there, so I won't repeat my self.

Or in short - use camera.unproject() method to get world coordinates from screen coordinates.

MilanG
  • 6,994
  • 2
  • 35
  • 64