This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Changing the sprite height during rendering

Changing the sprite height during rendering
by on (#30954)
Quick question: does anyone know for sure what happens if you change the sprite size during HBlank?

I'd imagine that since they were evaluated through the whole scanline with a certain height, the following scanline would show the sprites as if they had the previous height, but from the next scanline on, they'd be displayed according to the new setting.

That is, if a mid-frame $2000 write takes effect immediately. Has anyone ever tried this?

by on (#30985)
I just set up a test that put 8 sprites in a horizontal row in the middle of the screen, then changed height from 8x16 to 8x8 at various points during their rendering. As the change moved later and later, it took effect on the sprites from left to right, so it can be changed mid-scanline and affect only some sprites from that line. I set up a second test that did the same, then changed the size back to 8x16 a couple of scanlines later. The sprites appeared with a couple of rows missing, and again slowly changing from left to right as the change time moved forward. When I changed the test to start with 8x8, then change to 8x16 then 8x8 a couple of lines later, there were glitches to the right of the sprites during the change as the time passed through them.

So, I'd say you can change it during H-blank just fine.

by on (#30986)
Thanks for testing it out blargg. I haven't had much time near my NES, so I couldn't do this myself.

Now, I just didn't understand one thing:

blargg wrote:
When I changed the test to start with 8x8, then change to 8x16 then 8x8 a couple of lines later, there were glitches to the right of the sprites during the change as the time passed through them.

What do you mean "glitches to the right of the sprites"? Since the meaning of the tile index changes depending on the mode, I'd expect some weird patterns whenever that setting is changed. Are you saying something like that?

Quote:
So, I'd say you can change it during H-blank just fine.

By "fine" you mean "without unexpected glitches"? If I change their height during HBlank, along with the sprite patterns (through MMC3 bankswitching), what I'll see in the next scanline are the sprites that were evaluated using the old height, the old patterns, old everything, right? So, if the patterns were all transparent before, I'd see no sprites at all, but on the next scanline they'd be displayed according to the new parameters. Did I get that right?

EDIT: I'm really not sure about the patterns. I don't know if the sprite patterns are buffered during the evaluation or fetched as they are displayed...

by on (#30989)
Meh, I did another test and could switch height after the first 8 rows of the sprites had been drawn, either from 8 to 16 or 16 to 8, and have it appear properly. I was able to vary the switch time within a window of around +57 to +120 CPU clocks relative to the beginning of the scanline without glitches. So the answer is, yes you can change sprite height mid-frame without glitches.

by on (#30992)
Thanks blargg, I'll give this a shot soon.

Do you (or anyone else who knows about the sprite evaluation process) know exactly when the sprite patterns are fetched? If by any chance they are buffered during the evaluation process or if they are only loaded when they are displayed?