Sprite disappearing on certain conditions ???

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

Post Reply
User avatar
Orion_
Very interested
Posts: 52
Joined: Mon May 02, 2011 2:26 pm
Location: France
Contact:

Sprite disappearing on certain conditions ???

Post by Orion_ » Wed Feb 15, 2017 12:42 pm

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
Retro game programming !

User avatar
Natsumi
Very interested
Posts: 76
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: Sprite disappearing on certain conditions ???

Post by Natsumi » Wed Feb 15, 2017 1:30 pm

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.

User avatar
TmEE co.(TM)
Very interested
Posts: 2264
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: Sprite disappearing on certain conditions ???

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

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.
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

User avatar
Sik
Very interested
Posts: 511
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Sprite disappearing on certain conditions ???

Post by Sik » Wed Feb 15, 2017 11:21 pm

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.
Sik is pronounced as "seek", not as "sick".

User avatar
Natsumi
Very interested
Posts: 76
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: Sprite disappearing on certain conditions ???

Post by Natsumi » Thu Feb 16, 2017 6:55 am

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...

User avatar
BigEvilCorporation
Very interested
Posts: 188
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: Sprite disappearing on certain conditions ???

Post by BigEvilCorporation » Mon Feb 20, 2017 10:35 am

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!
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

User avatar
Natsumi
Very interested
Posts: 76
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: Sprite disappearing on certain conditions ???

Post by Natsumi » Mon Feb 20, 2017 11:23 am

Could always put at Y = 0 instead =P

User avatar
TmEE co.(TM)
Very interested
Posts: 2264
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: Sprite disappearing on certain conditions ???

Post by TmEE co.(TM) » Mon Feb 20, 2017 12:11 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest