OAM Sprite Attribute Bit 5 (Priority: front/behind BGR)

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
sdm
Posts: 412
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

OAM Sprite Attribute Bit 5 (Priority: front/behind BGR)

Post by sdm »

Playing Mystery World Dizzy, I noticed something I had not seen before (or did not pay attention). It's about hiding the object (sprites) behind the background (for example, a large pillar at the beginning of the game).
It is known that bit5 in the OAM attribute is responsible for displaying sprites behind or in front of background elements/tiles. Only from what I know, it works on all the elements of the background at the same time.
I wonder how it was done that the character / sprite smoothly enters behind pilar, but at the same time being partially visible on a completely different part of the background (front of the wall).

I am very curious how it was done.
Attachments
dizz.jpg
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: OAM Sprite Attribute Bit 5 (Priority: front/behind BGR)

Post by pubby »

If two sprites are overlapping, the overlapping pixels are determined by only one of them: the sprite lowest in OAM. If bit 5 of the lowest sprite is set, the overlapping pixels will be rendered behind the background, regardless of the other sprite's attributes.

In your image, I'm guessing that opaque sprites are being drawn where the columns are, and that these sprites have bit 5 set and are lower in OAM than the sprites of Dizzy. The overlap of these sprites with Dizzy will render as the background, thus creating the effect you see.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: OAM Sprite Attribute Bit 5 (Priority: front/behind BGR)

Post by tokumaru »

Yup, high priority (i.e. low OAM index) opaque sprites with the "behind the background" bit set, positioned along the edge of the column. If other sprites try to overlap those, they lose the battle because their OAM indices are higher, but then, when it's time to draw the winning high priority sprites, no sprite pixels are drawn because they are "behind the background".

This trick allows you to make sprite masks in whatever shape you need, as long as you don't blow your sprites-per-scanline budget.
sdm
Posts: 412
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Re: OAM Sprite Attribute Bit 5 (Priority: front/behind BGR)

Post by sdm »

Ok, everything is clear. Thanks. I did not notice that at the moment when the Dizzy touches the pillar, additional sprites are placed on the edge of the pillar.

A similar effect is in Wonderland Dizzy, but there visible Sprite overflow reveals the use of additional sprites to make the character hide behind the wall.
Attachments
dizzsproverflow.png
dizzspr.jpg
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: OAM Sprite Attribute Bit 5 (Priority: front/behind BGR)

Post by tokumaru »

Another game that uses this trick is Nightshade. The very first room in the game has a pillar in the foreground that allows you to observe this effect.
Post Reply