How can i use a y-axis down coodinate system?

Anything libgdx related goes here!

How can i use a y-axis down coodinate system?

Postby mzechner » Fri Mar 09, 2012 1:19 am

Hi,

your critique is duly noted. Libgdx is flexibel enough to allow any kind of coordinate system. While there have been a few "complaints" about our default coordinate system, most people seem to cope well with it.

I wrote a bit of code for you, demonstrating that using y-down is easily achievable with all 2D graphics classes. See [1], which is fully documented and should show you everything you need.

If this is to complex, painful or badlogical then by all means use AndEngine, it's sufficient for lightweight 2D games.

Also, i usually do not give individual support via e-mail, please use the forums at [2]. That way other's can benefit as well.

ciao,
Mario

[1] http://code.google.com/p/libgdx/source/ ... 482&r=3482
[2] http://www.badlogicgames.com/forum

Hi, Mario

I used to be keen on Flash game development, but as soon as I got my Android smartphone I immediately migrated to Android development. I was searching for a Flash equivalent for Android so that coding feels more natural, and I think that LibGDX's stage2D framework is perfect! However, there is a major drawback I'm sure you are aware of, and got me into thinking about using AndEngine instead - the origin point of every graphical object is at the lower left corner! It is very confusing for me, as I'm used to a coordinate system where the origin point is at the upper left corner.

I have read your book - Beginning Android Games. When showing how to build a framework, you mentioned that you preferred the y-up coordinate system because when Mario is jumping, it is more natural for his y coordinate to increase, rather than decrease. Although your logic is correct, it is not something a programmer can get used to, it is BADlogic. Keep in mind that all of us Flash developers, who want to migrate to Android development, would want to use a y-down coordinate system. It would be easier to port a game from Flash to Android using LibGDX that way. And the touch coordinates being from a y-down coordinate system makes everything even more difficult.

I made an app for myself to help me study my geography lessons, I wrote it in LibGDX, and the flipped coordinate system was real pain for me. The first thing I wanted to do after finishing it was finding another framework, which I didn't manage to.

I have searched for a way to fix the problem, and I have read your posts regarding it. You suggested flipping the TextureRegions vertically and then set the camera y-up property, but that makes all TextureRegions be upside down. Another fix I read, just making "y' = height-y" makes everything more difficult - the developer has to create a subclass of the texture regions, text fields, etc., and I'm a bit of a lazy person, like yourself.

Don't you think it would be more convenient for everybody if you fix the coordinate system? How hard could it be? I know I'm not the first one asking you to do this, but I also know I won't be the last. Besides, fixing it would make LibGDX irreplaceable :)

P.S.: And yes, I was considering using AndEngine, but its lack of documentation and not-so-good performance made me stick with your framework.

P.S.2: Great book, by the way! Helped me a lot.

Regards,
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: How can i use a y-axis down coodinate system?

Postby Saurav » Fri Mar 09, 2012 4:23 am

The thing that always gets me is the SpriteBatch draw functions that take texel coordinates for the source X and Y. I have to specify screen coordinates from bottom left, then texture coordinates from top left. Sometimes I cheat and just throw the textures into Sprites so I can do my math in a consistent coordinate space. For backgrounds and other non-moving textures, y = height - y is easy enough to do.

Not being a Flash programmer or a graphics guy, but having done some coordinate geometry in high school and college, origin at bottom left is far more logical for me than top left. X and Y increase to the right and up. That just seems... right :)
Saurav
 
Posts: 623
Joined: Sun Feb 27, 2011 7:59 pm

Re: How can i use a y-axis down coodinate system?

Postby Sippolo » Fri Mar 09, 2012 6:30 am

Honestly, if inverting the y-axis for all the calculations results in a such difficult thing, I can't imagine the rest of the development issues, so I guess LibGDX is surely not the best option in that situation :)
I agree with the above reply, I just find so natural to work with a cartesian axis system as I did at school, with quadrant One (up-right) being positive for x and y.
Sippolo
 
Posts: 70
Joined: Thu Jan 12, 2012 12:19 pm
Location: Italy

Re: How can i use a y-axis down coodinate system?

Postby mzechner » Fri Mar 09, 2012 6:53 am

Sippolo wrote:Honestly, if inverting the y-axis for all the calculations results in a such difficult thing, I can't imagine the rest of the development issues, so I guess LibGDX is surely not the best option in that situation


i hope you are being sarcastic. the code example illustrates that you dont need to do anything other than setting a boolean to a specific value.
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: How can i use a y-axis down coodinate system?

Postby Sippolo » Fri Mar 09, 2012 7:12 am

mzechner wrote:i hope you are being sarcastic. the code example illustrates that you dont need to do anything other than setting a boolean to a specific value.


That's exactly what I meant to express: a little bit of sarcasm.
I'm sorry, I thought it was obvious, maybe my english is not that good :D
The thought is: having the y axis upside down for personal preference is a 0 level "issue" in LibGDX development (as you demonstrated), not even having the courage to ask to "fix" it like someone did.

As always, you do a very nice work with both quality and support/documentation ;)
Sippolo
 
Posts: 70
Joined: Thu Jan 12, 2012 12:19 pm
Location: Italy

Re: How can i use a y-axis down coodinate system?

Postby Magnesus » Fri Mar 09, 2012 8:38 am

I quite like the y-axis up because I use Inkscape which uses the same coordinates system, so I can just copy positions from it. Really helps with putting things in the right places. (just set the page size in Inkscape to the same width and height as your scene)
Magnesus
 
Posts: 1654
Joined: Sun Sep 25, 2011 3:50 pm

Re: How can i use a y-axis down coodinate system?

Postby bigtunacan » Mon Mar 12, 2012 5:27 am

I'm also new to Libgdx. Honestly I'm more used to an origin of 0,0 being in the upper left corner; I think quite a few frameworks use this possibly because it matches up with most mouse and native screen coordinates. That said, it just isn't that big of a deal to work with one versus the other. The thing that I did find slightly odd though was that the Libgdx default screen coordinate system doesn't match directly up to the mouse coordinate system; so I always have the extra step to unproject my mouse coordinates to get screen space equivalent. Again though this isn't that difficult.

We can all find something to complain about if we look hard enough. I think overall Libgdx is a nice framework, and so far you've done a really great job of providing solid documentation and examples. When I was looking for an Android framework my first stop was at AndEngine, because they have better Google search results. I'm sure it is also a great tool, but the documentation and organization is seriously lacking. I know none of us like to create documentation, but it is a HUGE help to someone that is just jumping in to your framework. And there Libgdx is a clear winner. Good work!
bigtunacan
 
Posts: 4
Joined: Sun Feb 26, 2012 5:52 am

Re: How can i use a y-axis down coodinate system?

Postby Driant » Tue Mar 20, 2012 1:53 pm

This was about the first thing I looked for after setting up a project and learning about basic sprite drawing. Having a little experience on making simple games as Java Applets the inverse y coordinate was a bit tricky to get used to at first. But once you get used to it, it makes a lot more sense than the alternative.

Thanks for the explanation too, it'll help a lot of newcomers and people who just want to port their apps to android platform. Might come in handy for porting some of my older games in the future, if I decide to too :) cheers
Bricknoid: Brick Breaker, my first Android game
https://play.google.com/store/apps/details?id=com.bricknoid

Bricknoid 2: Brick Breaker, the sequel
https://play.google.com/store/apps/details?id=com.bricknoidtwo
Driant
 
Posts: 103
Joined: Mon Jan 09, 2012 8:02 pm

Re: How can i use a y-axis down coodinate system?

Postby NateS » Sat Mar 24, 2012 4:11 am

You are all wrong. Y down is the only way to go! ;)
NateS
 
Posts: 1980
Joined: Fri Nov 12, 2010 11:08 am

Re: How can i use a y-axis down coodinate system?

Postby nomadster » Mon Jun 11, 2012 1:01 pm

Hi Mario,

I am from Italy and used to speak italian since my first word. I was searching for a framework for Android game development so that coding feels more natural, and I think that LibGDX's stage2D framework is perfect! However, there is a major drawback I'm sure you are aware of, and got me into thinking about using BananaEngine instead: the class names are entirely in english!! It is very confusing for me, as I'm used to italian names.

I have searched for a way to fix the problem, and I have read your posts regarding it. You suggested to start learning english but I'm a bit of a lazy person, like yourself.

Don't you think it would be more convenient for everybody here in Italy if you fix the class names? How hard could it be? I know I'm not the first one asking you to do this, but I also know I won't be the last. Besides, fixing it would make LibGDX irreplaceable. :D

P.S.: And yes, I was considering using BananaEngine, but its lack of existence made me stick with your framework.

Cheers,
Alessandro
nomadster
 
Posts: 10
Joined: Sat May 12, 2012 6:01 pm

Next

Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest