LibGDX has a coordinate system where (0,0) is at the bottom-left. (like this image: http://i.stack.imgur.com/jVrJ0.png)
This has me beating my head against a wall, mainly because I'm porting a game I had already made with the usual coordinate system (where 0,0 is in the Top Left Corner).
My question: Is there any simple way of changing this coordinate system?
If you want to hide the transformation and not think about it after setting it up once, you can make a class that inherits all of the functionalities you need, but first transforms the coordinates before passing it to its parent class's function. Unfortunately, this would take a lot of time.
You could alternatively make a method that does the simple
y' = height - y
transformation on the wholeCoordinate
object (or whatever it is you're using), and call it once before each operation.If you use a Camera (which you should) changing the coordinate system is pretty simple:
If you use TextureRegions and/or a TextureAtlas, all you need to do in addition to that is call region.flip(false, true).
The reasons we use y-up by default (which you can easily change as illustrated above) are as follows:
The only two places in libgdx where we use y-down are:
Again, you can easily change the used coordinate system to whatever you want using either Camera or a tiny bit of matrix math.
I just made a class that extends
SpriteBatch
that overides certain methods addingy = Gdx.graphics.getHeight() - y - height
. Simple but effective.Not sure if this helps anyone or not but I was able to get textures and fonts rendering correctly using the suggested flipped coordinate system via OrthographicCamera. Here's what I did:
Important things to notice are:
Now we will see if I am back here later tonight doing edits to fix any other issues or discoveries with doing all this. :)
Interesting graphics library, I would say. I found this assessment from the link below:
http://www.csc.kth.se/utbildning/kandidatexjobb/datateknik/2011/rapport/ahmed_rakiv_OCH_aule_jonas_K11072.pdf
Just to expand a little on what badlogic said above, if you are using a TextureAtlas (with TextureRegions) you need to flip them, as badlogic said, in addition to the camera work. If you are using a TextureAtlas, you can use this code right after loading your atlas: