0

I am really new to Libgdx and game-programming ... That's my hobby

I have downloaded some images for a very easy city game. Its very simple to build a "one layer" map (Drawing Isometric game worlds) ,

Here it comes : an "eaxmple" for using a collection of images ! But as you can see on the image there is a background(blue) ... and then there are theese highrise buildings(red).So it's all multilevel and it fits perfect togehter ... So my question is : What is the best way to build something like this or are they any patterns for rendering? How can I display tiles in different height steps ?? For example a Bridge (e. g. like in TheoTown)??

an image example

Community
  • 1
  • 1
DranikMan
  • 27
  • 4
  • I think I found a quiet good solution for this http://codereview.stackexchange.com/questions/92095/isometric-city-building-game ... but whats with different heights? – DranikMan Jun 28 '16 at 13:44

1 Answers1

0

Try sorting buildings by a z-index. In this case that would mean buildings closer to the bottom of the screen (regardless of their height) should be drawn last.

Here's an example of what I would do:

public class Building implements Comparable<Building> {
    //render, constructor, etc.
    public int compareTo(Building b) {
        return b.y - y;
        //sort buildings based on their distance from the bottom of the world
    }
}

In your rendering code, first sort the list of buildings, then draw:

Collections.sort(listOfBuildings);
for (Building b : listOfBuildings) {
    b.render();
}

I hope this helps! Btw, i can't test this right now, so it's possible that the drawing would be completely backwards, where the buildings at the top are drawn before the buildings below. If thats the case, play around with the compareTo method.

hujasonx
  • 106
  • 3
  • this works pretty good : `for(int z = mapLayerCount-1; z >= 0; z--) { for (int x = 0; x < mapWidth; x++){ for(int y = mapHeight-1; y >= 0; y--){ //RENDER ` ..... and then just go on with rendering like this :....... `screenX = (cellX * tile_width / 2) + (cellY * tile_width / 2) screenY = (cellY * tile_height / 2) - (cellX * tile_height / 2)` – DranikMan Jun 28 '16 at 18:48
  • Thanks for your help!!! But after searching a while , I decided to use a z coordinate ... like above --> – DranikMan Jun 28 '16 at 18:55
  • But I don't know how can I build a bridge ... or just a block "one level" higher , because the z cordinate sorts only the drawing "order" ... but I need something like a skyscraper ..,(picture) – DranikMan Jun 28 '16 at 19:41
  • assuming you draw the skyscraper all at once, the z coordinate you used should work i think. Not sure i understand your issue, but if you're trying to get something to appear "in the air," try sorting it as you would as if it was on the ground. Then, for sort objects with the same z-index by their height, and render in the new order. If I helped in any way, I would appreciate an upvote and/or green check (: – hujasonx Jun 28 '16 at 20:14
  • Oh sorry :) I forgot ... no problem – DranikMan Jun 29 '16 at 05:48