Latest Uploads
Invasion V ... prototype

rychan

Invasion V ... Prototype

rychan

Shields 64x64

Pakz

Ffs_Spam

Jayenkai

Hives Screen shot

rychan

Rpg Potion Sprites

Pakz

Forum Home

Z ordering

UserMessage
Posted : Friday, 24 June 2016, 14:11 | Permalink
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 | Permalink
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 | Permalink
Dither


Brilliant, thanks, GfK! I will give that a try and let you know how it goes.
Posted : Saturday, 25 June 2016, 13:30 | Permalink
Dither


Worked perfectly, thanks again for your help.
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 670|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Latest Posts
Favourite Amstrad CPC Games
steve_ancell Sat 21:02
Shoutbox Topic - 319
steve_ancell Sat 20:52
Inside Donald Trump
rockford Sat 12:09
Any Feature Requests?
Jayenkai Sat 09:36
More Monkey Madness - With Ducks
rockford Sat 05:13
Arms on Switch
rockford Sat 05:02
Time for a new Android Test Doohickey
Jayenkai Fri 09:26
CSS-Me-Do - SoCoder2
Jayenkai Fri 06:28
Pillowcases for kids!
rockford Thu 16:15
Manchester Arena Explosion
Jayenkai Thu 02:04
More

Latest Items
Showcase : Hives
zzoom Fri 16:10
Dev-Diary : My Journey into NES Development
rychan Thu 12:31
Showcase : Flappadiddle
Jayenkai Sun 14:39
Snippet : QFind
Jayenkai Sun 13:02
Showcase : Tiny Blocks
Jayenkai Sun 04:08
Showcase : Read Error A
rychan Fri 05:13
Blog : All my makes!
Jayenkai Tue 05:48
Showcase : Infinitron
rychan Mon 18:03
Showcase : Quadoban
rskgames Fri 10:11
Blog : My Arduino experience.
steve_ancell Wed 17:02
Showcase : Roguelike Explorer
Pakz Fri 06:59
News : Newsletter #311
Jayenkai Thu 17:27
Link : Super Shapes Exploration Kit
Andy_A Thu 11:09
Dev-Diary : Sensitive - Arduboy!
rychan Thu 17:27
Snippet : Skylines
steve_ancell Tue 14:25
More

Who's Online
steve_ancell
Sat, at 21:32
9572AD
Sat, at 18:50
therevillsgames
Sat, at 18:00
rockford
Sat, at 16:19
shroom_monk
Sat, at 16:02
Jayenkai
Sat, at 15:42
spinal
Sat, at 12:08
rychan
Sat, at 08:56
rskgames
Sat, at 07:21
Pakz
Sat, at 04:16
Link to this page
Site : Jayenkai 2006-Infinity | MudChat's origins, BBCode's former life, Image Scaler.