Sprite Viewer and questions

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Sprite Viewer and questions
by on (#51838)
I implemented an OAM viewer and noticed right away that games do weird stuff with sprites. As an example, I recorded it during the intro of SMB1. I am curious why the sprites flicker. I know why the Mario sprites flicker...because he actually flickers when he gets bigger or smaller. However, I wasn't expecting the other sprites to do so. Another example, Zelda seems to move sprites around.

SMB1 (8MB AVI)
Zelda (2MB AVI)

Anyone have any decent explanation for why this is done?

by on (#51839)
Looks like "OAM cycling", it's a workaround for the 8 sprites per scanline limit. The NES will only display the first 8 sprites found on a scanline. If you've got 12 sprites on a single scanline you move objects around in sprite ram so that they will take turns being among the 8 first sprites.

If letters represent sprites on a single scanline:

; sprites A - H will be visible
A B C D E F G H I J K L M N O

; sprites E - L will be visible
E F G H I J K L M N O A B C D

This of course causes flickering if a scanline has more than 8 objects. That's why some emulators have the "no sprite limit" option - this option will also draw the remaining sprites that would have been invisible on a real NES and reduce flicker.

Of course, that first part of SMB does not have 8 sprites on a single line, but think of when you've got a bunch of goombas in front of you and shoot a fireball - the goombas will start flickering until one of them dies and jumps off the screen. Without OAM cycling, one of the goombas (or the fireball) wouldn't have been visible at all.
Re: Sprite Viewer and questions
by on (#51842)
NESICIDE wrote:
Anyone have any decent explanation for why this is done?

Contrary to what programming guides for newbies might have people believe, games don't usually hardcode game objects to OAM positions. This is because different objects of different sizes can be active at any given time, and because some randomness is desirable for sprite cycling.