2D Beatemup Zordering? Think Final Fight

BlitzMax Forums/BlitzMax Beginners Area/2D Beatemup Zordering? Think Final Fight

Amon(Posted 2007) [#1]
Any example code or techniques to get the effect of zordering sprites, like in beatemups?

How would I code this to draw characters according to their positions?

My first idea was to use the y axis. I would store the y position in a field of a type and if the yposition was > or < the targets then do the relevent drawing.

Problem is it doesn't work or I'm doing something stupid. I'm definately leaning towards me doing something stupid.

Any help would be appreciated.

:)


tonyg(Posted 2007) [#2]
In light of no other responses : I would probably use a specific 'Z' field and sort the spritelist against it.


Sledge(Posted 2007) [#3]
My first idea was to use the y axis...it doesn't work

Are you setting the handle of each sprite to the bottom?


FlameDuck(Posted 2007) [#4]
1) Store all your sprite objects in a TList (or Array if you have a lot of them).
2) Make a compare() method in your sprite object that works on the Y coordinate.
3) Sort the TList before you draw it.


tonyg(Posted 2007) [#5]
I might have this wrong but, if you use the 'Y' coordinate, won't it behave badly if the character jumps (if they can jump in Amon's game).


Sledge(Posted 2007) [#6]
That's a good point - he's going to need another field to keep track of the yoffset of the image from the ycoord base for jumping. May as well call that ycoord 'zPos' or something similar, because that's what it is.


Matty(Posted 2007) [#7]
A way I do it, similar to the others is this:
Separate your drawing from your logic first.

1. Create a single dimension array the height of the game world.

2. As part of your regular 'creature update' code get the 'y' value of the 'feet' of your sprite (remembering to allow for any offset due to jumping).

3.Use this y value as an index to the array mentioned above. At that index create a bank, or resize if it already exists, and add the creature's handle into the bank (or some other identifier such as the image handle/frame to draw).

4. After finishing your logic update you will have a list which is presorted and holds each image frame or creature handle which you can pass to your draw routine.

5.In the draw routine run through the array from top to bottom, if a bank exists at each index run through all the creatures in that bank and draw them

6.I know this should go to the start but it makes more sense when explaining to put it here: reset and clear all banks at the start of your next logic update.