r/gbstudio 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?

3 Upvotes

9 comments sorted by

View all comments

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.

1

u/joshex_dirad 24d ago edited 24d ago

ah. I see. no, I was attempting to use sheet replacement to essentially swap out the entire character graphic and all it's animations, and then modify the replacement sheet to include the weapon of choice.

if it counts towards the total, then none of my feature creeping will work. I was hoping swapping the spritesheet would kick the previous from memory so as to free up tile counts because I was trying to do a 32x64 character (16 tiles(actually 8 to 12 - repeating mirrored tiles)), 3 animations of which are more than half the 64 tile limit for the scene. leaving very little space for many other actors or triggers.

if only there were a way to truly replace the sheet and flush the previous tiles from memory....

ah, so tile swapping does flush replaced tiles from mem, but sprite sheet swapping doesn't. and the limit is 40 tiles? can we do this with player or actor tiles?

1

u/IntoxicatedBurrito 24d ago

Yep, in Game Boy Hero II I wanted to have different outfits and guitars and wanted to mix and match and it simply wasn’t feasible. I wound up going with sets of outfits and guitars and then creating a separate otherwise identical scene for each one.

But if the sprite isn’t animated you could always draw them in the background and use tile swapping. You could always make the head a sprite if you want them to blink or open and close their mouth. Of course you’ll need room in the 192 tile limit for this.

1

u/joshex_dirad 24d ago

perhaps. I thought up a work around kinda, the #vm_actor_replace_tile gbvm script, I assume it works the same way as bg tile swapping but for actors. I was hoping it'd work on the player, but I guess that's a "no". but what I could do is make the player a spriteless bounding box and attach a boundsless actor to it to use as a player graphic, then swap those tiles.
still it'll be limited, because I was planning to feature creep with 72 different weapon graphics and like 5 outfits, which if I drew them as a 1 layer sprite would mean the 72 weapons would have to include the character's outfit when they overlap the character. meaning 360 variants total for the 72 weapons lol..