Advertisement

How to calculate the piority in 2D ?

Started by May 09, 2000 11:44 PM
6 comments, last by nlo 24 years, 7 months ago
Hi, How FinalFight style games (2D) calculate the sprites piority to draw them, smaller "Y" draw 1st and bigger "Y" draw later.
Hi nlo,

My guess is that sprites with a lower value y (assuming 0,0 is the top left of your screen) are regarded as further away, and drawn first, just as you have said. If the bottom of one sprite is higher up on the screen than another, it is "further away" in the fake-3d world, so it is drawn before the other.

So your "depth" priority would be based on the y value of the bottom of the sprite, lower y is drawn first. This would create correct overdraw (if any occurs).

Hope that was helpful

-------------
squirrels are a remarkable source of protein...
Advertisement
Hi,

on computers with hardware sprites (like most old 8-bit computers -> C64, MSX and many others) which could display say 32 sprites at the same time, sprites were just drawed in the order they are in memory, so sprite 0 is drawn first and sprite 31 is drawn last (or the other way around ). If you give a sprite an additional variable (lets call it z) you can use it to determine the drawing order.

Bad Monkey: nice idea, but not completely correct. In side-scrolling shoot ''em ups a lower Y value doesn''t mean it''s further away, it just means it''s higher up on the screen.


-my 2 cents-
--------------------------Programmers don't byte, they nibble a bit. Unknown Person-------------------------
A Z Buffer pops into mind... .

-----------------------------------------------------------
PCMCIA - People Can't Memorize Computer Industry Acronyms
ISDN - It Still Does Nothing
APPLE - Arrogance Produces Profit-Losing Entity
SCSI - System Can't See It
DOS - Defunct Operating System
BASIC - Bill's Attempt to Seize Industry Control
IBM - I Blame Microsoft
DEC - Do Expect Cuts
CD-ROM - Consumer Device, Rendered Obsolete in Months
OS/2 - Obsolete Soon, Too.
WWW - World Wide Wait
MACINTOSH - Most Applications Crash; If Not, The Operating System Hangs
D''oh!

Looks like I didn''t think that one through... if the sprite jumps (ie, leaves the pseudo-ground), its y value decreases, and my idea generally goes to shit

Thanks for picking me up on that one Arjan (sometimes my stupidity amazes even me )

-------------
squirrels are a remarkable source of protein...
I would give each sprite a depth value. The further sprites are drawn before the closer sprites.

-Icarus
-Andreas
Advertisement
thankz everyone !

but i have no idea how to implement Z/depth value...
can someone give me some example(s) ?!

thankz for help !!
Try something like this :

struct sprite
{
int x;
int y;
int z;
}

sprite game_sprite[SIZE];
int sprite_order[SIZE];

void game_loop()
{
make_sprite_move()
fill_sprite_order_with_game_sprite()

for ( int i=0; i{
display( game_sprite[sprite_order]);
}

}

You'll need some kind of sort algorithm. You can find some of them on gamedev.net or in any algorithm book.

Hope it will help!


Edited by - Prosper/LOADED on May 12, 2000 11:19:16 AM

This topic is closed to new replies.

Advertisement