How to calculate what entity is drawn first (2D java rendering using Slick2D)
<h2><strong>Explanation:</strong></h2>

<p><strong>EDIT3: MASSIVE CLEAN UP as this was not clearly explained.</strong></p>

<p>I'm trying to build up a 2D level out of tiles and entities. Where the entities are <strong>for example</strong> trees that can be cut. I need to store the data (how many chops are left for example) for each entity. I want them to have a more dynamic position (doubles) and a more dynamic sprite-width and height. My tiles are 32x32 pixels whilst my trees are not going to be one tile but a sprite with greater height than width.</p>

<p>I want objects that are closer to the top of the level to be drawn before the other objects. In this case a character behind the tree will cannot be rendered in or in front of the tree. This case also applies to other objects of the same kind (like trees).
I think it might be too inefficient to loop through the entities and calculate each entity's  position since there may be a LOT of entites in the level.</p>

<p>As I've done some research I found that certain libraries allow the storage of both the object and it's position in a MAP (BiMap in google's Guava).</p>

<h2><strong>Questions:</strong></h2>

<ul>
<li>Is this an inefficient manner.. but are there some changes that can<br>
be applied to make the rendering more efficient (if so, what could be
optimized)?</li>
<li>Or is this an inefficient manner to render the entities    and is
there a better way (if so, what other methods are there in    Java)?</li>
<li>Or is there something else that I haven't listed?</li>
</ul>

<p><strong>EDIT2:</strong> I looked through the link I've posted in the edit below.
It seems that Google's Guava (I think that's all correct) has BiMaps. Is there an equivalent to this in regular Java? Otherwise Google's Library will probably be able to fix this for me. But I'd rather not install such a huge library for this one interface.</p>

<h2><strong>At last:</strong></h2>

<p>It's very much possible that the answer has been right in front of my nose here on StackOverflow or somewhere else on the internet. I've tried my best searching but found nothing.
If you've got any suggestions for search queries or any relevant links that might be of use to me I would appriciate it if you'd post them in the comments.</p>

<p>Thanks for taking the time to read through this/helping me ;)</p>

<h2><strong>EDIT:</strong></h2>

<p>I have looked at; <a href="http://stackoverflow.com/questions/3027538/efficient-mapping-of-game-entity-positions-in-java?rq=1">Efficient mapping of game entity positions in Java</a> .
I think it's narrowly related to this question. But I think it's just not what I'm looking for. I am going to look through the second answer very closely since that might be able to solve this for me.. but I'm not sure.</p>

<h1><strong>SOLUTION</strong></h1>

<p>The solution is to have an array, arraylist or another manner to keep track of your entities. Every tick/update you'll take all the object's Y coordinates and store them in another array/arraylist/map/other with the same size as where the entities are stored in. On every equivalent position to the entity you'll store it's Y. Then you'll order it with another loop or using <a href="http://www.leepoint.net/notes-java/data/arrays/70sorting.html" rel="nofollow">http://www.leepoint.net/notes-java/data/arrays/70sorting.html</a> .</p>

<p>Then when rendering:</p>

<pre><code>for(int i = 0; i &lt; entityArray.length; i++)
entityArray[i].render();
</code></pre>

<p>Off course you'll render it more efficiently by rendering only whats on or near your screen.
But that's basically how one does this in 2D top-view/front-view.</p>
