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.
[SOLVED] Z order drawing
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Z order drawing
Last edited by var77 on Wed Jul 11, 2018 2:37 pm, edited 1 time in total.
Re: Z order drawing
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.
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.
Re: Z order drawing
Thanks grump for your answer.
After a noon of test i try to handle it i found what i was searching on the forum there viewtopic.php?t=10628.
That was what you wrote draw them by adding a Z value and "sort" them.
In my case the swaping order is not a real problem i guess i could deal
with it for the moment.
After a noon of test i try to handle it i found what i was searching on the forum there viewtopic.php?t=10628.
That was what you wrote draw them by adding a Z value and "sort" them.
In my case the swaping order is not a real problem i guess i could deal
with it for the moment.
Who is online
Users browsing this forum: No registered users and 201 guests