gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > BG with Sprites at different priorities

#56394 - wiz - Sat Oct 08, 2005 12:58 pm

Hello!

I'm not entirely sure if this is curable, but here is the problem;

I have a screen in mode 4, which displays a picture. I also have moving sprites on the screen, some are set to be behind the picture and some are infront. All that works correctly but when a sprite "behind" and a sprite "infront" of the picure enter the same coordinates you can see the sprite which is "behind" the picture appear in front of the picure (but still behind the top sprite)

Hopefully that makes sense, is this a known problem and is it fixable?

Thanks!!

#56406 - tepples - Sat Oct 08, 2005 4:25 pm

Are you making sure that the sprite in front has a lower index in OAM than the sprite in back?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#56496 - gauauu - Sun Oct 09, 2005 2:42 am

tepples: do you mean that when sprites overlap, the index in OAM takes precedence over the sprite priority you set? I'm a little confused.....

#56501 - tepples - Sun Oct 09, 2005 3:09 am

Yes, the OAM index takes precedence over the sprites' background priority when two sprites overlap. The 2-bit priority is used only for sprite-background interactions.

Here's a model for how the compositor works on the NES, the Super NES, and the GBA:
  1. Sort all backgrounds from front to back based on their priority.
  2. Render backgrounds, preserving each pixel's priority in a Z-buffer.
  3. Render sprites in OAM index order with lower-numbered sprites on top, preserving each sprite pixel's priority in a Z-buffer.
  4. Combine the two buffers, putting the frontmost background pixel in front if it has a lower-numbered priority than the frontmost sprite pixel.

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#56510 - gauauu - Sun Oct 09, 2005 6:25 am

Interesting....slightly non-intuitive, and different than some of the tutorials describe, but good to know.

Thanks for the detailed description!

#56533 - wiz - Sun Oct 09, 2005 1:54 pm

oh! err, yes that fixed it ! one thing I forgot to mention in my original post was the sprites are double sized and scaling etc, which is where I thought the problem was coming from. but nope, as it now works fine!

thanks for the great explanation too :)

*smacks head*