Hi everyone i came back here to ask a little question about drawing order.
I wanted to know if actually there are any way to control drawing order.
To be more precise i know there is this tricky tutorial https://love2d.org/wiki/Tutorial:Drawing_Order
but in my issue i got random object that not appear at the same time.

For example imagine that you want a simple Space Invader (galaga) and
want to control the drawing Z order of random incoming enemy, is that possible ?

Thanks in advance.

Last edited by var77 on Wed Jul 11, 2018 2:37 pm, edited 1 time in total.

You can use the sorted table approach as shown in the tutorial. Keep your enemy sprites in a table and keep that table sorted according to a z value that you assign each enemy. Draw sprites in the order they have in the table.

table.sort is not a stable sort though. Enemies with the same z value will swap order. A better approach would be to use binary search to find the correct insertion location, this keeps the list always sorted and stable.