Weird problem with sprites

SGDK only sub forum

Moderator: Stef

Post Reply
matasiete
Interested
Posts: 10
Joined: Thu Jan 25, 2018 6:21 pm
Location: Spain
Contact:

Weird problem with sprites

Post by matasiete » Tue May 14, 2019 5:01 pm

Hi,

Just for learning how to work with the SGDK and before facing more complex projects, I'm coding a port of Jetpac from ZX Spectrum. I have no previous experience coding games at all and it's quite some years since I touch C for the last time, so I'm starting from scratch almost in every aspect.

I have more or less ready the structure of the levels, the jetman movement, the basic behavior of the enemies, the physics and the collisions between them (everything "inspired" by the samples coming with the SGDK). For sure not in a very orthodox nor optimal way, but that will come later.

I have 2 different modes, a ZX mode where I'm trying to replicate the ZX original pixel perfect and a MD mode where I'm adding some changes, e.g. the platforms are not always located in the same positions.

So far so good.

The thing is yesterday I started to work on the spaceship and I've run into a problem with the sprites. In the first level the rocket starts broken in 3 different parts, each in a different position. No behavior or collisions yet, just displaying the 3 parts (each part is a sprite).

The problem. When started in the ZX mode the 3 parts are displayed well, but when started in MD mode the sprites are corrupt, they look kind of mingled with the sprite of the jetman.

See a couple of screen captures:

Image

Image

The thing is the code that creates the sprites is exactly the same. Nothing changes. One thing: The rocket sprites are created right before the jetman, if I do it right after then they still are shown corrupt, but only one of the parts.

The code is already upgraded to SGDK 1.40, but the same happened with 1.34.

This happens with Gens Kmod as well as in real hardware, though in the real MD after 3 or 4 times that the MD level is started they are displayed well.

This is a very simple scenario so I'm sure I'm missing something. Anyone has any clue what might be cause?

The problem is reproduced in this branch:
https://github.com/diegomtassis/md-jetp ... pt_md-mode

And this is the bin:
https://github.com/diegomtassis/md-jetp ... ut/rom.bin

matasiete
Interested
Posts: 10
Joined: Thu Jan 25, 2018 6:21 pm
Location: Spain
Contact:

Re: Weird problem with sprites

Post by matasiete » Tue May 14, 2019 6:33 pm

Some more info.

The differences between the modes are 3 right now:
* Position and size of the platforms.
* Position of the parts of the rocket.
* Initial position of the jetman.

If I keep everything equal then no problem with the sprites.

If I change only one of the 3 differences, then the sprites of the rocket get corrupted, regardless which one of the 3 things I change.

Going back to the having the 3 things equal. I try progressively changing the definition of the floor (in the ZX mode it has a length of 32 tiles). Well, up until 16 tiles everything works fine but when I specify a floor length of 15 tiles then the sprites of the rocket get corrupted. Weird.

hotrodx
Very interested
Posts: 50
Joined: Thu Mar 21, 2019 1:23 pm

Re: Weird problem with sprites

Post by hotrodx » Wed May 15, 2019 3:07 am

Looking at Blastem's VRAM viewer, the sprites do seem get overwritten when running MD mode on the first run.

Not a full-on fix, but I removed the FAST compression in your sprite.res so that it loads the sprite data linearly. On my test, the rockets now appear correctly in MD mode on first run.

If you won't be using that many sprites, perhaps you can leave it uncompressed for the time being while you investigate the issue further.

Also, make sure your variables are re-initialized properly on soft reset. I notice that when resetting, the ZX / MD mode menu "remembers" its old position, so you may have other variables not being re-initialized properly. Soft resetting keeps variables in memory (and the reset button on the MegaDrive is equivalent to a soft reset).
Attachments
jetpac_no_compression.zip
(53.31 KiB) Downloaded 197 times

matasiete
Interested
Posts: 10
Joined: Thu Jan 25, 2018 6:21 pm
Location: Spain
Contact:

Re: Weird problem with sprites

Post by matasiete » Wed May 15, 2019 8:55 am

hotrodx wrote:
Wed May 15, 2019 3:07 am
Not a full-on fix, but I removed the FAST compression in your sprite.res so that it loads the sprite data linearly. On my test, the rockets now appear correctly in MD mode on first run.
Thanks for the effort hotrodx.

True, removing the compression definition of the sprites in sprite.res solves the problem. Also changing from FAST to BEST.

Another workaround I found (with some help), keeping FAST compression, is to add a VDP_waitVSync(); after the creation of the level but before entering the game main loop.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Weird problem with sprites

Post by Stef » Wed May 15, 2019 9:32 am

Don't use BEST compression as it will slowdown a lot sprite update, you can keep NONE or FAST.
I tried to have a look in your code but couldn't really find any "problems". Did you try to use 'debug' compilation ? So you can see error messages in GensKMod output dialog ? That is really useful to find errors as 'out of DMA capacity or out of memory error".

matasiete
Interested
Posts: 10
Joined: Thu Jan 25, 2018 6:21 pm
Location: Spain
Contact:

Re: Weird problem with sprites

Post by matasiete » Wed May 15, 2019 10:46 am

Ok, I'll go back to FAST compression, which works if I add the extra VDP_waitVSync().

I haven't tried debug mode yet. I'll give it a try and I will come with the result.

Post Reply