Can depth sorting be done with GameBase?
utaner opened this issue · 4 comments
I'm trying to make a top-down game using GameBase. I'm curious if I can sort the depth of the player with the objects in LDtk. I couldn't find any documentation about this on the Heaps.
Take a look at Const.hx. There are some constants for layers that you can use to do this, I believe.
…
On Sun, Mar 3, 2024 at 1:48 PM Taner Uçar @.> wrote: I'm trying to make a top-down game using GameBase. I'm curious if I can sort the depth of the player with the objects in LDtk. I couldn't find any documentation about this on the Heaps. — Reply to this email directly, view it on GitHub <#107>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYYRX5H4MSQRV23ID6JI3DYWOLBZAVCNFSM6AAAAABEEIZFJSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE3DKNJYGQYTIMI . You are receiving this because you are subscribed to this thread.Message ID: @.>
It seems more like for UI, am I wrong in thinking so?
I'm trying to make a top-down game using GameBase. I'm curious if I can sort the depth of the player with the objects in LDtk. I couldn't find any documentation about this on the Heaps.
If you check the Tenjutsu source code, I do exactly that:
https://github.com/deepnight/ld51-tenjutsu-48h/blob/e9f516411fc457a25d2fb56d60453a0a3bd6ed88/src/game/Game.hx#L406
Basically:
- I have my "sortable" entities in an array or something
- Every XX frames, I sort this array based on whatever criteria (here, the Y coordinate)
- I call
h2d.Layers
"over()" method to re-order the display list based on the array order.
If your entities are not in a h2d.Layers
, you may simply re-call "addChild()" for all elements using the array order. Works exactly the same.