Hi all,
Had an idea for a flexible system for handling drawing actors, collision objects, etc in GameMaker Studio 2 and thought it might be useful to other people - for some of my older projects I used the good old "depth=-y" thing, but ideally I'd like to avoid generating endless garbage layers in the Step event. So I figured I could handle drawing everything in a single object - that solves a lot of problems anyway, but there are still many ways to skin the depth-sorting cat at this point.
Also, I really wanted to avoid using data structures for this - I love them for handling things like a deck of cards, but for practically anything else, nah I like to be able to add/remove instances of things with reckless abandon.
I went with the idea of using a For Loop to draw actor object sprites based on dividing the height (the Room Height in my case, but this can be defined in any way) by a variable for control over granularity.
So, somewhere in the Create Event of my StageHandler (controller) obj, I have:
//ForLoop Init
count_slice_max=32; (set lower for less accuracy, and vice versa)
count_slice_current=0;
And in the Draw Event in my region for actor handling I check for my object archetype, use the loop:
for (count_slice_current=0;count_slice_current<=count_slice_max;count_slice_current+=1) { // with() and BBox Check and Draw in here }
Manipulate each actor object via with() and then I check where their "touching the ground" position is. There's probably a better way of doing this, but here's how I got it working:
if bbox_bottom>=(room_height div other.count_slice_max)*clamp(other.count_slice_current,0,other.count_slice_max)
and bbox_bottom<(room_height div other.count_slice_max)*clamp(other.count_slice_current+1,0,other.count_slice_max)
{ //Draw Here }
Then if those conditions are both met, the actor draws its sprite there. To get more accuracy in the sorting, I can just adjust the count_slice_max variable - 4 is super rough, while 64 seems to work just as well as "depth=-y" visually.
Maybe reducing count_slice_max mid-game like dynamic resolution scaling would even work if it was ever needed to balance out expensive things happening in the game or something, no idea. Feel free to suggest improvements! I'm an artist in my day job, definitely 100% not a real programmer ;)