Page 1 of 1

Sprite disappearing on certain conditions ???

Posted: Wed Feb 15, 2017 12:42 pm
by Orion_
It's been a week that I'm trying to find a bug in my gameplay code about a strange sprite "disappearing" for no reason.
I couldn't find any bug in my gameplay code, so I started to try some test on sprite display, and I found that the "bug" is coming from the Megadrive itself, but I can't figure out why.

Here is my test, I display 3 sprites on the same line, one outside of screen and 2 on screen.
Then I display another 4th sprite on the same line at coordinate X = 0, and suddenly, one of the 2 visible sprite, disappear !
what kind of sorcery is this ??
(Also, I have the same behavior when X = 512 (but not when X = 513 ??))
For now my workaround is, I won't display the sprite if X/Y <= -32 or X/Y >= 320/224

Image

Re: Sprite disappearing on certain conditions ???

Posted: Wed Feb 15, 2017 1:30 pm
by Natsumi
Sprite masking. When there is a sprite with X=0, the lines are masked and no sprite will show up there. This should apply to both of these sprites however, I do not understand why it doesn't. The fix? If X=0, add 1 to X. This will in some rare cases offset sprites but it will work just fine. Make sure you also check for X&$1FF=0, because the VDP will treat X=512 as X=0. Sonic games do this and I am assuming most other games do too.

Re: Sprite disappearing on certain conditions ???

Posted: Wed Feb 15, 2017 9:39 pm
by TmEE co.(TM)
EDIT:

Code: Select all

During rendering, sprite with X coord of 0 can be used to clip sprites with lower priority if it isn't the highest priority sprite on that line. There needs to be at least one higher priority sprite on that line first before clipping can be done, if that condition is satisfied then all lower priority sprites on that line get clipped, their data fetches happen but they don't get rendered. Sprite 0 cannot be used to clip other sprites as it is the highest priority sprite. This feature is useful to prevent sprites from appearing on HUDs or other areas where any overlap is not welcome.
I'm slowly writing a nice document while I am making a game, testing things on hardware and documenting the results.

Re: Sprite disappearing on certain conditions ???

Posted: Wed Feb 15, 2017 11:21 pm
by Sik
Natsumi wrote:Sprite masking. When there is a sprite with X=0, the lines are masked and no sprite will show up there. This should apply to both of these sprites however, I do not understand why it doesn't. The fix? If X=0, add 1 to X. This will in some rare cases offset sprites but it will work just fine. Make sure you also check for X&$1FF=0, because the VDP will treat X=512 as X=0. Sonic games do this and I am assuming most other games do too.
Don't forget that X=0 on the attributes is actually X=-128 on screen (i.e. already way off screen). So really, just remove it. Heck, just remove any sprites that aren't visible on screen and you avoid all problems and also avoid wasting sprite pixels.

Re: Sprite disappearing on certain conditions ???

Posted: Thu Feb 16, 2017 6:55 am
by Natsumi
I just now realized this is true... So technically this hack in Sonic games shouldn't be needed! I'll go test few things, be back to you with results.

Apparently this happens on the damn title screen. That's mildly stupid...

Re: Sprite disappearing on certain conditions ???

Posted: Mon Feb 20, 2017 10:35 am
by BigEvilCorporation
Natsumi wrote:Sprite masking. When there is a sprite with X=0, the lines are masked and no sprite will show up there.
How did I not know this? You've just solved a load of my problems, I keep sprites at X=0 to "hide" them!

Re: Sprite disappearing on certain conditions ???

Posted: Mon Feb 20, 2017 11:23 am
by Natsumi
Could always put at Y = 0 instead =P

Re: Sprite disappearing on certain conditions ???

Posted: Mon Feb 20, 2017 12:11 pm
by TmEE co.(TM)
I did Y=0 instead of X=0 in my first MD game when I discovered this haha.