Sprite disappearing on certain conditions ???
Moderators: BigEvilCorporation, Mask of Destiny
Sprite disappearing on certain conditions ???
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
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
Retro game programming !
Re: Sprite disappearing on certain conditions ???
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.
-
- Very interested
- Posts: 2442
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
Re: Sprite disappearing on certain conditions ???
EDIT:
I'm slowly writing a nice document while I am making a game, testing things on hardware and documenting the results.
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.
Last edited by TmEE co.(TM) on Thu Feb 16, 2017 2:17 am, edited 1 time in total.
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
Re: Sprite disappearing on certain conditions ???
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.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.
Sik is pronounced as "seek", not as "sick".
Re: Sprite disappearing on certain conditions ???
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...
Apparently this happens on the damn title screen. That's mildly stupid...
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Re: Sprite disappearing on certain conditions ???
How did I not know this? You've just solved a load of my problems, I keep sprites at X=0 to "hide" them!Natsumi wrote:Sprite masking. When there is a sprite with X=0, the lines are masked and no sprite will show up there.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
Re: Sprite disappearing on certain conditions ???
Could always put at Y = 0 instead =P
-
- Very interested
- Posts: 2442
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
Re: Sprite disappearing on certain conditions ???
I did Y=0 instead of X=0 in my first MD game when I discovered this haha.
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen