-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|618|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Basic Basement -> Z ordering

Posted : Friday, 24 June 2016, 14:11
Dither
I have a bunch of game objects* -- player, enemies, bullets, etc. -- some of which are stored in structured linked lists (a list of enemies, list of bullets, etc.)

Each of these objects is of a structured type containing a field to store its y coordinate.

I would like all the objects to be drawn in ascending order from lowest y coordinate to highest (i.e. drawn from top to bottom of screen).

I know how to sort an individual list...but how would I deal with objects across multiple lists, and some that might not be in a list at all?

Thanks for your time.

*Not using "object" in the OOP sense.
Posted : Friday, 24 June 2016, 14:15
GfK
Make a new list, with a new type of object containing image handle, x, y, scale, rotation, all the rest of it. When something has to be drawn, just create an object with the required info and put it in the list instead.

Then when you're done, sort the list by y-coordinate, then just iterate through and draw them all in one hit.

That's how I'd do it.
Posted : Friday, 24 June 2016, 14:21
Dither
Brilliant, thanks, GfK! I will give that a try and let you know how it goes.
Posted : Saturday, 25 June 2016, 13:30
Dither
Worked perfectly, thanks again for your help.