Sorting for 2D Drawing
- by Nexian
okie, looked through quite a few similar questions but still feel the need to ask mine specifically (I know, crazy).
Anyhoo:
I am drawing a game in 2D (isometric)
My objects have their own arrays. (i.e. Tiles[], Objects[], Particles[], etc)
I want to have a draw[] array to hold anything that will be drawn.
Because it is 2D, I assume I must prioritise depth over any other sorting or things will look weird.
My game is turn based so Tiles and Objects won't be changing position every frame. However, Particles probably will.
So I am thinking I can populate the draw[] array (probably a vector?) with what is on-screen and have it add/remove object, tile & particle references when I pan the screen or when a tile or object is specifically moved. No idea how often I'm going to have to update for particles right now. I want to do this because my game may have many thousands of objects and I want to iterate through as few as possible when drawing.
I plan to give each element a depth value to sort by.
So, my questions:
Does the above method sound like a good way to deal with the actual drawing?
What is the most efficient way to sort a vector? Most of the time it wont require efficiency. But for panning the screen it will. And I imagine if I have many particles on screen moving across multiple tiles, it may happen quite often.
For reference, my screen will be drawing about 2,800 objects at any one time. When panning, it will be adding/removing about ~200 elements every second, and each new element will need adding in the correct location based on depth.