A downloadable tool

Download NowName your own price

Swap Tiles Plugin  for GB Studio 3.1-3.2

New Version - 2.1.0

Tileset X and Y now accept variables.  If upgrading from 2.0 the tileset x and y values will probably default to 0 so beware!

New Version - 2.0.0

Version 2.0 offers a bit more streamlined interface as well as the ability to use variables for the x and y coordinates in the scene.

This new version is not compatible with previous versions. I've therefore changed the display name to "Swap tiles var" so that projects using the previous version don't break when using version 2.

Version 2 only supports 16 block mode, meaning your tileset should be organized in 16x16 blocks (or 8x8) like the picture below.


If you don't want to worry about unique tiles in the tileset, set the scene type to "Logo". You then won't have to make placeholder tiles to fill up the row.


How to install

Download and extract the zip file into the root of your project directory.

Ex:

The resulting folder structure should be : C:\PATHTOPROJECT\PROJECT_DIRECTORY\plugins\SwapTiles\events\eventSwapTiles.js


About:

This plugin is mostly a quality of life script as it replaces the time consuming task of adding GBVM commands line by line and having to worry about pushing and popping values to the stack.

Instead just plop a few values into the event script and you'll be animating tiles in no time!

You can choose to change 1 or more tiles, either 8x8 or 16x16 as well as how many frames you wish to be animated.

For infinite loop animations this event should be put into an actor's update loop (alternatively a timer). The wait time between frames is entered directly into the event script.

Besides animating your rivers and waterfalls, you can use this plugin for HUDs, menus, and other graphical changes to your scene.


Guide 

For more information about tile swapping please read:

https://gbstudiocentral.com/tips/animating-background-tiles-3-1/

First let's prepare our tile sheets. In order to swap tiles we first need to create a new scene with a tile sheet consisting of all the tiles we want to swap. As of version 2.0 tiles of size 16x16 should be placed in a 16x16 block (as opposed to 8x8 tiles consecutively.) If you want several frames of animation the tiles have to come directly after each other. If you change the scene type to "Logo" all tiles will be treated as unique. Otherwise you need to make sure that all tiles are unique yourself.

Example of a onetime swap:


For our game scene we need to insert unique tiles where we want the tiles to be swapped, or else every tile that shares the same 8x8 image will change. In the above picture I used letters and symbols to make sure the tiles are unique in the scene.

Now that everything is set up we can insert the script from Add Event->Plugins->Swap Tiles Var. If placed in an on init, the script will be run once. If you want a continuous animation place the script in an actors On Update.

- Tilemap is the tileset you'll be swapping with. After creating a scene with your tileset, you will be able to find and select that tileset with the dropdown menu. (You can also add this manually using the advanced settings)

- Tile Size is how big the tiles you want to swap are, either 8x8 or 16x16.

- Frames of animation are how many frames are in your animation, for a one time swap input 1. 

- Frames betwen swaps if animating are how many frames you want to wait before the plugin swaps to the next frame of animation.

- Number of tiles to be swapped are how many tiles you want to swap at the same time. In an update loop all these tiles will be swapped before moving to the next iteration.

When swapping 16x16 tiles you only need to specify the coordinates of the top left tile. In the above picture x= 9, y = 6  corresponds to the tile showing the letter "D" but the whole block will be replaced with the ribbon in the tileset scene with the starting coordinates 14, 3.

Example of animated swap:


This example shows how you can easily animate tiles. The block showing "@APQ" will be replaced with an animation that counts up from 0 to 9 every 10 frames.  Only the starting frame needs to be set, and the plugin will automatically move to the next consecutive block until it reaches the set amount of frames of animation before going back to frame 0. 

Scene X, and Scene Y coordinates can also be set using variables. Currently this isn't an option for Tileset X and Y, but I might update this at a later date.


I hope this script speeds up your development time!

The following scene will only take around 3 minutes after setting up the tile sheet:


(Please excuse the gif compression)


StatusReleased
CategoryTool
Rating
Rated 5.0 out of 5 stars
(11 total ratings)
AuthorFredrik
Made withGB Studio
TagsGame Boy, gbstudio, plugin
Code licenseGNU General Public License v3.0 (GPL)
Average sessionA few seconds
LanguagesEnglish
LinksSource code

Download

Download NowName your own price

Click download now to get access to the following files:

SwapTilePlugin-2.1.0.zip 3 kB
SwapTilesPlugin-1.1.1.zip 16 kB

Development log

Comments

Log in with itch.io to leave a comment.

(+3)

Hey there! I quickly put together a basic 'how to' video for your plugin :) I'm planning to make a more "professional" one in the future but thought I'd get this out quick as I've seen some friends getting confused. Hope this helps anyone who comes to the comment section confused about the basics!

(1 edit)

Getting an error for some reason:
Error: Compiling "FO_EVENT_SWAP_TILES_VAR" failed with error "TypeError: Cannot read property 'symbol' of undefined". {"scene":"UI Items","scriptType":"scene"}

Using GBS v 3.2.1

(1 edit)

I had that problem, but then realized I did not actually place the scene that I was swapping from into the game. Not sure if that helps

Deleted 3 days ago
(1 edit)

Do you think you could upload a demo project? Im really struggling to use the plugin, and it definitely is my own lack of experience with GB Studio but i think actually seeing how it works in practice in a working project would really help! Also is there a way to only replace one tile? It seems like the plugin is replacing all similar tiles instead of only the one i specified, I'm trying to make an animated cutscene for context, do you know if thats possible with your plugin?

I too would benefit from a demo.

(2 edits)

maybe it sounds dumb but anyway to add 16x24 size ?

or more size options i general ?

i love this plugin but for my project (a giana sisters port)i can´t use it full potenial ,

 the tiles are to wide if i go with the original sprites and tile size  from the c64 they are in a 16x24 format ^^

Should be possible! I’ll see if I can add it this weekend.

Is there any way you'd be willing to update this to accept variables for the Tileset X & Y? That would be beyond useful for me... 

I'm trying to make a card game, so I made a random number switch case for picking the card tiles position (not realizing there's no way to supply a tile x & y value in the plugin).

I actually tried editing the plugin myself, but I got a little lost towards the appendRaw() calls...

I suppose there's always the GBVM, but you've spoiled me with the 16x16 tile option!

(+2)

I’m working on an update to support variables for tileset X and Y too. It’s a little bit more complicated cause the underlying GBVM command expects a single constant representing the memory index of the 8x8 tile, so I’ll have to do a bit more math in GBVM and then push the final result as a constant, and then repeat that 4 times with differing memory indices. But it should be possible! Just need to pour myself some extra coffee and power through it :’)

(+1)

Just updated it by the way!

Hey there! I think this plugin is going to really help me, but I'm running into an issue. I want to use it to remove some background text I put in the scene using the Background Text Plugin. 


I use the "Display Background Text" event, and then I try to call the "Swap Tile Event" and replace the text I just displayed, but the text is still there? For instance, I write the display text at X = 2, Y=2, then I try to replace the tile at those same coordinates, but it doesn't work. Any suggestions on what I might be doing wrong?

Text is stored in another place in memory, so you’ll probably have to use the display background text event again to overwrite the tiles (with spaces or an empty character). Alternatively you can call “VM_CALL_NATIVE b_scroll_repaint, _scroll_repaint” in a GBVM script to repaint the whole scene to its original image.

(1 edit)

Hi !
Thank you for this great plugin !
Just I have a problem to use it with custom script with sceneX and sceneY given by parameters.


the call

My script



The result seems change the tile 0x0 instead the tiles 25x9 and 25x10 of my scene.


If I put the script directly on the scene and not use variable for sceneX and sceneY it works


Thanks

Huh, interesting! I’ll look into it. In the meantime it will work if the script references global variables, which you can set before calling the script.

Yes I have used global variables instead function parameters and it works !

Thank you

First, thank you for making this. It simplifies the process a lot.

Just want to throw it out there that I'm experiencing the same issue with the method juicelink uses as well.

Referencing globals resolves it as you suggested, though this does end up creating a lot of extra global variables when trying to make a UI with numbers that change (displaying dynamic stats for example)

Being able to pass in variables, or even better, being able to set the Tile X and Tile Y to variables, would make this plugin even more useful.

Hi, yeah supporting properties is definitely something I want to implement. I might have to restructure the logic a little bit, but it’s definitely worth it.

custom scripts I’m a bit more worried about. It might just be a GB studio quirk where references to references just don’t work well in custom plugins.

Seems like references to references don't work well in the built-in plugins either sadly :\

Hello, I am currently using this plugin, and it has become indispensable for me when creating games. I truly appreciate your work.

Regarding the plugin, many Japanese users face challenges due to limited proficiency in English. I've taken the initiative to localize it into Japanese, including some additional explanatory notes. May I have your permission to distribute this Japanese version of the plugin to others, specifically on a Discord server dedicated to indie game developers in Japan, such as those using GBSTUDIO? (I won't distribute it elsewhere.)

If redistribution is not allowed, would it be possible for you to handle the distribution?

Thank you for your guidance on this matter.

返事遅くなってすみません。そう言ってくれて嬉しいです。はい、配布して大丈夫ですよ!新しいバージョンを公開したんですが、よかったらそのバージョン使ってください。

日本語を勉強中なので、そのDiscordサーバーに興味があります。参加させてもらえませんか?

Thank you!
I'm very happy.

Here is the Discord link: https://discord.gg/QXzdSJ9g

I appreciate it.

(1 edit)

this is saving time thanks! playing around so far nice. however i replace a tile in x y using swaptile and it seems many (checkered) tiles are being replaced. where can i see how to fix to just 1 tile?? thanks

Hi! If you want to change just one tile, that tile has to be unique. The swap changes the tile in memory, so any other tile using that memory address will also be changed.

Hi cant seem to configure it.. do you have a sample file i can see? thnx

Yeah sure: https://drive.google.com/file/d/1iIRS9UulKmjMs62bvowcK3h_sQ84Nj-4/view?usp=sharing

So on the right side, all flowers are animated, but on the right side, only one is animated. This is done by making the flower on the right side unique.

(1 edit)

thanks i see how its set up, but not sure how to modify. I added a "unique" tile to 12   2  coords and changed the setting but it still doesnt change but shows the other unique tile. .for example:

 i  hope link works now https://drive.google.com/file/d/1EqUs_kxdSfQkJ9IlPU44qUsLiexEzI54/view?usp=shari...

Seems to be working as expected. The tile on 12,2 changes from the letters to the flower tiles. If you’re wondering why the color is pink, it’s because of the tile’s palette color, and the reason its not animated is because the script is on init and not on update, and the reason there are artifacts is because the tiles aren’t aligned.

Great plugin! I'm still getting the feel for it, but already getting better results than when I've been wrestling with GBVM scripts directly 😵

Daft question maybe, but I'm planning to use this for a Gallery mode in an upcoming commercial release - is that permitted under the licence? (Just making sure; I haven't charged up-front for any of my games before... 😌)

(+1)

Yes! Commercial releases are fine! The GNU license is very permissive!

Good to know, thank you very much! 👍

(3 edits)

I keep getting an undefined global error and I can't figure out why. I'm following the steps exactly, changing the names of my tilesets to what the error shows (when it's incorrect), all my file names are unique, and all tiles are unique. I also added placeholder tiles to fill that last row (not pictured).

If I'm swapping 16x16 tiles with a 16x16 block tile sheet mode, does each individual 8px block within each 16x16 tile need to be unique?

Any help would be appreciated!!! Thanks so much for making this tool!

(+1)

Hi! The error means that the gbvm can't find your tileset file. Is the tileset saved in the file "tileset2.png"? If it is and you are still grtting errors then GB studio might have made another internal name for it. If so try making a GBVM script event, add reference, and find what the file is called internally. If it's something like "__bank_bg_tileset_2_tileset" than enter tileset_2 into the tilemap name.

For unique tiles you can change the tileset scene type to logo and all tiles will automatically become unique. Hope this helps!

Well I tried it again today and it's all working correctly! So we're good! Regardless, your explanation makes a ton of sense. I knew that was a thing based on the other comments here, but I was definitely looking for the wrong names in the wrong spot lol. Thanks again!

Deleted post

What part do you need help with?

Deleted 145 days ago
Deleted post
(+1)

If you just want snow/ rain in a certain area, like the sky, then you can just use the tile-swapping animation feature like normal on the tile representing your sky. But if you want an extra layer of snow over your whole map, then you would probably want to create a couple snow sprites and change its position randomly over your map.

Deleted post
(1 edit) (+1)

 getting an error when using this now, any help on what to do?

Im getting the same error im going to see what if i can figure it out in anyway

Hi! It's hard to troubleshoot without seeing a screenshot of your setup, but make sure that the tileset.png is set as a new scene, and that the name of the png-file is both unique and without spaces. You can hit me up on discord if you need more in-depth help!

i got it thanks

I'm getting the same error, how was this resolved?

I did it hard way 

(1 edit)

Fantastic plugin, thank you so much. Just wanted to ask: when I swap the tiles on map, then leave the map, it goes back to original when I reenter that map? 

(+1)

Hi thanks! You'll probably want to use a variable to keep track of the swaps. So when you perform a swap you also set a variable to true, then on scene init you can check if the variable is true or false and swap accordingly. 

Thanks for the answer :)

The "Unique Tile 1's X" and "Y" only take static numerical values. Is there a way to pass variables? I would like to make a game where the player can flip the tile they're standing on, which requires a variable.

Hey sorry for the late reply, been a bit busy with non gb related work!

When I have time I'll try to update the plugin with the ability to pass variables.  I'll probably have to rewrite the logic somewhat though, since plugins don't have access to variables values. All math will have to be done using gbvm in runtime (as opposed to precompiled). 

This is awesome! I learned how to tileswap a couple months ago but this makes it even easier to do! Thanks for making this, iit's going to help alot of GBstudio learners

(+1)

what a god send to all noob/level 1 gb studio devs. or just lazy people like me! thank you for the hard work!

Hey thanks! I appreciate it :). I love your work by the way, good stuff!