Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

nlo

How to calculate the piority in 2D ?

This topic is 6916 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, How FinalFight style games (2D) calculate the sprites piority to draw them, smaller "Y" draw 1st and bigger "Y" draw later.

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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-

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
I would give each sprite a depth value. The further sprites are drawn before the closer sprites.

-Icarus

Share this post


Link to post
Share on other sites
thankz everyone !

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

thankz for help !!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!