I'm working on a game that uses an isometric view, and one thing I need for this is to sort the sprites representing mobs according to their depth on the screen. In displayio the drawing order is determined by the order of elements in the displayio.Group, and I'm wondering what would be the best way of keeping it sorted:
- Create a list out of the group, sort it, and then create a new group, with all the items from the sorted list appended to it. Do this every time the positions of sprites have changed.
- Perform bubble sort, or similar simple sorting algorithm on the group directly.
- Create a new kind of group in C, called
DepthGroup, and add a depth attribute to everything that can be added to a group. Automatically track changes to that attribute and sort the group as needed before displaying. Anything that wraps those items can have its own code to update depth as needed.
- Add a
sort method to Group that would behave as on any other Python collection.
- Some other way I didn't think about.
I wonder what are your thoughts about this? I want to try working on this, though if we choose option 4, I will probably need some help.
I'm working on a game that uses an isometric view, and one thing I need for this is to sort the sprites representing mobs according to their depth on the screen. In
displayiothe drawing order is determined by the order of elements in thedisplayio.Group, and I'm wondering what would be the best way of keeping it sorted:DepthGroup, and add adepthattribute to everything that can be added to a group. Automatically track changes to that attribute and sort the group as needed before displaying. Anything that wraps those items can have its own code to updatedepthas needed.sortmethod toGroupthat would behave as on any other Python collection.I wonder what are your thoughts about this? I want to try working on this, though if we choose option 4, I will probably need some help.