Sprites in Crystal hack glitch when walking

I'm basing this off the pokecrystal disassembly.

My hack of Crystal has added a bunch of new maps, and I assigned them to the 26 map groups according to which roof color I wanted. I then realized that each group also has a list of 23 valid sprites for outdoor maps (i.e ROUTE or TOWN) so I checked which sprites each map needed and made sure that they were all listed in the appropriate group.

However, I'm still getting glitches when sprites move. A sailor might appear normal standing still, so I know the correct sprite is being loaded, but the walking animation shows up as letters and numbers.

Here's my modified engine/overworld.asm with comments on each map group listing its outdoor maps. Can anyone see what the problem is? Do sprites have to be in a certain order? The bug seems related to sprites being different sizes, like SPRITE_YOUNGSTER has frames to walk but SPRITE_STANDING_YOUNGSTER doesn't, but I don't know what needs changing.

Re: Sprites in Crystal hack glitch when walking

You sure the problem isn't something as simple as font being loaded while the sprites are trying to move?You can check out with VBA or BGB what Video Ram looks like at any time. When moving sprites are loaded, all the people events that appear on the map should have both their standing and walking sprites totally loaded into VRAM.And when font is loaded, it replaces most if not all the walking sprites so when the people events move around, the graphics are loaded from the offset where they should be, but there is some font data there.

If the issue is something bigger and is indeed related to coding, let us know.

Edit:Also, just remembered that you can actually use only 11 walking people events in each spritesheet / map group. The remaining 2 sprites should be something that are not moved (= item ball, fruit tree, rock smash stone etc.).

Edit2:I thought you had meant 13 instead of 23 as being the sprite limitation for map group as I remembered that was the limitation for Gold and Silver, but it's actually 11. I guess it's possible that you can put that many sprites into the map group, but this probably means that the bug you're getting comes from the fact that not all of the sprites you're meaning to use in a map can fit into the area in VRAM that is reserved for them. At least, I think that's the problem but I may be wrong.

Re: Sprites in Crystal hack glitch when walking

Thank you! That does sound correct; some of my map groups use a lot of sprites, and they're the ones where I noticed this bug.

However, it looks like the limit might be 9 walking sprites, not 11. Fuchsia City is in Group 17 and uses 10 walking sprites, the last being YOUNGSTER. Looking at the VRAM I see the first 9 sprites loaded in order on the right (after the player sprite, before the two still sprites), and YOUNGSTER is loaded on the left, where his walk animation overlaps the font. The same thing happens in National Park, part of Group 3, where the 10th walking sprite also happens to be Youngster and thus glitches. That seems... annoyingly low. Oh well.

Re: Sprites in Crystal hack glitch when walking

Right - you can only use 9 walking sprites and 2 standing sprites in each map group. I actually checked that out between "Edit 1" and "Edit 2" and was meaning to write that there in an understandable way, but by accident (as I was thinking already ahead...) just wrote this "I thought you had meant 13 instead of 23 as being the sprite limitation for map group as I remembered that was the limitation for Gold and Silver, but it's actually 11." which doesn't really say that clearly at all. Also, that's bad english there in overall as well...

Anyway, yeah... you have to be able to work with only 9 walking sprites in each map group. It's totally possible, but you'll have to use generic sprites here and there on outside maps. If the map isn't ROUTE or TOWN though, you don't have to worry about this problem.

I would consider making it so that you mark each "unused slot" of each map group with some sprite you hardly even use (pokecenter nurse maybe?) in outside maps. That way you can keep track of which map groups have unused slots for new sprites and how many there are.

Re: Sprites in Crystal hack glitch when walking

The reason the font is loaded at all is because Crystal shows you the name of the map you just entered. You really don't need the whole font for that... there's space from 1:9600 on for the letters making up the name instead of the whole font.

You can get rid of it by stubbing LoadOverworldFont in misc/mobile_41.asm.

LoadOverworldFont::
ret

To get rid of the map name box (which will now have garbled text), remove the call to ReturnFromMapSetupScript.inefficientcallba in engine/events_3.asm.

Since the game assumes the font is always there, it also never thinks any sprites need to be reloaded when you stop talking to someone. This used to be the case in Gold. The easiest way to add it back is to add the following to LoadOverworldFont:

LoadOverworldFont::
callba Function14157
ret

This just reloads the sprites. This will reintroduce some lag that was already in Gold, but it's a little worse since there's twice the sprites. You could add code that only reloads the font area, and call that instead. Follow the calls in Function14157 to see what you would need to adapt.

The game also avoids drawing sprites to the font area. To fix that, remove the check for bit 5 of wSpriteFlags:

Unused slots aren't a bad idea. But probably the best way is to refactor AddOutdoorSprites to use terminated lists (or lengths) instead of MAX_OUTDOOR_SPRITES, since the capacity is based on the size of the sprites, not how many there are.

There's another change that avoids drawing junk data, which reduces lag a bit. The full diff is below.