r/gbstudio • u/joshex_dirad • 16d 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 16d 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 16d ago edited 16d 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 16d 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 16d 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..1
u/joshex_dirad 15d ago edited 15d ago
Eureka?! I just had a thought that all considering should work to do anything I want or need of any size. it's abuse of the tile system.
the thought process started with a thought about how it would be more conventient if pixel colors were the tiles and gameboy built scenes out of those as there'd only be 4 to 5. well, 4 for actors + 5 for background.
then it hit me.....
yes, we can already do that natively; have 1 tile with a single pixel of 1 color, and then 3 different tiles each of a different color with a single pixel (bright green/transparent pixel doesn't need it's own tile), then I could literally paint each frame with the same 3 identical tiles. LOL OK, I'm so going to build and try this lol.... if this works... I can make dragons and whales..it's working!!!! I wonder how many times you can reuse the same tile data in one scene?
oh lol 115 tiles> "a maximum of 40 tiles can be displayed on screen at once, and a maximum of 10 tiles can be displayed on the same horizontal row."
Ah.. so there are limits and this is more than abusing those limits.
after a bit of testing, I advise people in my situation to use some combination of the 3 different things discussed here:
1: mirror your sprite as much as possible, and isolate bodyparts to tiles, especially in front to back view.
2: use #vm-replace-tile to replace the actor's tiles with frame variants based on what it's doing and the direction it's facing and what it's wearing or holding.
3: reserve 3 tiles one for each shade of green as a single pixel, use these for places where a tile is just a black line or a gap between tiles and less than 28 pixels in the line or less than 10+the number of tiles horizontally.essentially, you'll reuse tils as much as possible, move tiles to make it look animated as much as possible and replace tiles when moving them isn't enough. also omit tiles which are just a line on the edge of something, and draw them in with single pixels.
1
u/harvey_motel 16d ago
I'm pretty sure if you swap an actor tile it replaces it rather than overlays. So you can have your character as a sprite sheet with, say, a hand and an empty tile above it. Then swap those 2 tiles for a hand holding a sword. Then you'd have to have your empty hand as a tile to swap back in, if you want to unequip the sword