How to invert Y axis? When I touch on bottom or top of the screen, the Y value is opposite I want
-
May be something `height - y`? – Vlad Oct 13 '19 at 05:24
2 Answers
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.

- 2,864
- 1
- 12
- 21
-
my Y 0 value is on top. Do you know how to do to take Y 0 on bottom? – user10751746 Oct 13 '19 at 02:21
-
That could be done but it requires a formulae to transform your coordinate system because the original is at the top left corner of the screen. – Javier Silva Ortíz Oct 13 '19 at 02:26
-
To do that 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. – Javier Silva Ortíz Oct 13 '19 at 02:40
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.

- 6,994
- 2
- 35
- 64