Java, LibGDX and rendering isometric maps.
Hello there, my name is Kristian and I am the programmer of TSS. We thought it would be nice to post a little solution to how we handle isometric maps with LibGDX as there were some problems getting it to work. This post will only scratch the surface of how our rendering system is implemented, but if there's more interest in the subject, we can wright a much more detailed post about this later.
LibGDX is a powerful opensource framework for creating games with Java, and this is the framework we decided to use for Terminal System Seven. Personally, I think LibGDX is an amazing framework and would recommend people to use it for Android games any day of the week, but I also feel that doing things from scratch is a very good lesson. I thought the support for Tiled maps and the Tmx map loaders in LibGDX would make my life as a programmer alot easier and that this would save us alot of development time. I was wrong. It turned out that the Isometric part of the Tmx loader, map and renderer were still experimental and was only good for rendering static maps with no objects or entities moving around. This meant that LibGDX had no way of sorting custom moveable units into the draw order of the isometric map.
The first solution to this problem was to alter the existing source code ( LibGDX is open source ;) ), which kind of worked. This presented a big issue that broke pretty much everything with the rendering a bit down the road though. LibGDX preserves the concept of layers that Tiled uses, which works very well when it comes to top-down games. This isn't very well suited for isometric maps as the rendering isn't sorted in the same way. In isometric maps everything is drawn from the top down and from left to right in the following way.
for( y = mapHeight -1; y>=0; y--)
for( x =0; x < mapWidth; x++)
This is partly how we do it but we also render every cell of the map from the bottom up, which makes it easy to stack drawable objects on top of each other. Each cell of the map is constructed like a bucket so adding and removing objects to the draw order is simply a matter of finding which cell the object is on top of and add that object to that cell. Moving from one cell to another isn't much harder. First remove the object from the cell it was standing on and then add it to the cell it moved to.
A graph illustrating the differences between our rendering system and LIbGDX's.
Something that I've found to be very important when it comes to creating an isometric game is to keep track of which coordinate system you are working in. In our case the isometric coordinates are never used or accessible by us ( me, the programmer ). It is calculated by the rendering part of the engine once it's time to show everything on the screen. This is because it is alot easier to perform calculations, such as collision detection and finding a specific cell when everything is in an axis aligned coordinate system.
That's all for this time. As I said it just scratches the surface of how the rendering works. If you have any questions or want a more in-depth look at it just give me a shout. Either by commenting or sending us an e-mail.