title: Render multiple heights in an isometric tile based map
body: <p>Good evening everyone.</p>
  
  <p>I've been messing a bit with isometric tile worlds and I have a few doubts about rendering the elements on it.
  When I build a single height map I render it first and then add the diferent elements on top, and the displacement of the last seem right.</p>
  
  <pre><code>public void render(Graphics2D g2d) {
      for(int i = 0; i &lt; tileGrid.length; i++) {
          Point isop = NeoMath.getInstance().cartToIso(i % yAmmount, i / yAmmount, GlobalDataStorage.tileWidth, GlobalDataStorage.tileHeight);
          TileManager.getInstance().getTileByID(tileGrid[i]).render(g2d, isop.x, isop.y);
      }
  
      for(Entity entity : entityList) {
          entity.render(g2d);
      }
  }
  </code></pre>
  
  <p>(The position of the entity is calculated inside it's update).</p>
  
  <p>With this I have no problems as everything is rendered on the same height, the problem comes when I try to add other floors to it.
  Let's say that I want it to have three heights. I have a list of list of tiles instead of the single array, and render every element on them:</p>
  
  <pre><code>    public void render(Graphics2D g2d) {
          int flag = 0;
          for(int i = 0; i &lt; tileGrid.size(); i++) {
              Point isop = NeoMath.getInstance().cartToIso(i % yAmmount, i / yAmmount, GlobalDataStorage.tileWidth, GlobalDataStorage.tileHeight);
              for(int k = 0; k &lt; tileGrid.get(i).size(); k++) {
      TileManager.getInstance().getTileByID(tileGrid.get(i).get(k)).render(g2d, isop.x, isop.y - (GlobalDataStorage.tileZ * k));
              }
          while(flag &lt; currentList.size() &amp;&amp; 
            currentList.get(flag).getPosition().equals(new Point(i % yAmmount, i / 
            yAmmount))) {
              currentList.get(flag).render(g2d);
              flag++;
              }
          }
      }
  </code></pre>
  
  <p>Where the currentList is the list of entities.</p>
  
  <p>With this I have the problem that, when the entities move to a new position, they get overlaped by the tiles, as these are rendered after the entity, and the position of the entity does not change until it reached the destiny. I could change the position to the new one before rendering, but that implies that in the other axis the previous tile get rendered after the entity, making it disapear for a second due to the overlap.</p>
  
  <p>This also mess when I try to draw selection rectangle as it get stuck behind the tiles being rendered. I don't want them to overlap the whole map so can't draw them after all the rendering has been done either.</p>
  
  <p>Does someone know of another approach that I can try out?</p>
  
  <p>Thank you beforehand. </p>