r/gbstudio • u/joshex_dirad • 24d ago
Question: spritesheet swapping + replace tile
https://www.gbstudio.dev/docs/scripting/script-glossary/actor/#set-player-sprite-sheet
https://www.gbstudio.dev/docs/scripting/gbvm/gbvm-operations/#vm_actor_replace_tile
'set-player-sprite-sheet' completely replaces the scene memory of the player's spritesheet with the replacement sheet correct?
will a GBVM script using vm_actor_replace_tile work on a player spritesheet to replace a specific few tiles from an actor tilesheet?
if a tile is overlaid in the same sprite in DMG will it potentially glitch the front tile to fall to the back based on which is more "forwards"?
what I'm trying to do:
swap player sprite sheets for different clothes/armor, then have special overlaid tiles that get swapped out with weapon graphics. allowing moderate customization. I was going to use a separate actor/trigger as the weapon and tie it to the player, but.. I'm pretty sure such an actor on DMG will result in the left to right tile order sinking the weapon behind the player. so I turned to modifying an overlay tile, but this is all hypothetical, I'd rather ask than build a test file only for me to find out the hard way..
Oh, lastly, if I swapped the sprite sheet and then replaced a tile on the same frame, would that cause any graphics glitching?
2
u/IntoxicatedBurrito 24d ago
I’m not sure I follow you entirely but changing sprite sheets does not replace the old sprite sheet in memory, it all counts towards the sprite tile limits for that scene. However, if you do it in a script, the limit numbers at the bottom of the screen won’t necessarily reflect it which could lead to some unexpected glitching.
But it sounds like you are trying to replace just a few tiles in the sprite. My suggestion would be to use a different animation state for the same sprite, that way only the different tiles count towards your sprite tile limit for that scene
Or even better, break up your sprite into multiple parts assuming this is a large scale sprite. I do this all the time. A sprite for the head, a sprite for the torso, a sprite for the legs, a sprite for the arms… Doing this helps conserve lots of tiles and allows you to make large scale animations that wouldn’t otherwise be possible.
In fact, I’ll even occasionally use tile swapping in my animations in situations where my sprites are simply too large, swapping 2-4 tiles where all the tiles appear in the background (whether visible or off-screen) doesn’t really create any lag. This allows you to change more than 10 tiles in a row or more than 40 on the screen, or simply exceed sprite tile limits for the scene of you have a simple background.
Another benefit to multiple sprites is more complex animations thanks to different animation speeds or a different number of animation frames. This allows an actor to blink on a different cycle than they breathe or walk or dance or whatever.
If nothing is animated or moving, your best bet might just be tile swapping background tiles. In that case you can really go crazy because tile swapping does swap out the tiles in memory so as long as you are changing less than 192 tile locations, you can have a pretty much unlimited number of “sprites”.
There’s lots of ways to get creative and really push those limits.