[SOLVED] Z order drawing

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
var77
Prole
Posts: 25
Joined: Wed May 02, 2018 1:57 pm

[SOLVED] Z order drawing

Post by var77 » Wed Jul 11, 2018 10:31 am

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.

grump
Party member
Posts: 431
Joined: Sat Jul 22, 2017 7:43 pm

Re: Z order drawing

Post by grump » Wed Jul 11, 2018 11:17 am

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.

var77
Prole
Posts: 25
Joined: Wed May 02, 2018 1:57 pm

Re: Z order drawing

Post by var77 » Wed Jul 11, 2018 2:37 pm

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. ^^

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests