Open derekgates opened 12 years ago
Sorting the array of units on every iteration would be taxing on the system right? I wouldn't bother with it if it will.
Well, I wouldn't suggest sorting every time.
We can have the master list of all tanks, like we have now (so we can check ALL units). Then include other sets of specific types; one for planes, one for tanks (and whatever else that needs Z-Index to be taken into account).
An item is created and put into the main Tanks Set and then the corresponding set for it's type (again, only for ones that need accurate z-index).
A draw comes in, paints the items from the actual tanks (low-zindex set) and then the planes (high z-index set).
Wouldn't the special set (purpose of knowing the pseudo z-index) require the X,Y coordinates, the angle, etc to properly read out the draw requirements? Also, removing two entries when a unit is defeated and maintain indexes, that could prove difficult.
I don't know, suppose I'm missing the idea here. We could shelf this issue until we rework the structure and other things of Tanks.js.
Due to the rendering pipeline, we can draw planes under other 'tanks'.
Since we don't sort by the type, a plan can render under a tank depending on where it is in the list.