Place Atlas Tiles With Gdscript
I have this atlas:
Now, I want to set cells of the TileMap with tiles that are inside the atlas. The index of my atlas is 0. You can see the index at the side of the tile name:
If we try to use
the first subtile of the atlas will appear by default:
How can we select a specific subtile? With the last argument of the set_cell function. The last parameter is a Vector2 with a default value of (0, 0). To select the tile of the atlas we want to set, we can just specify the subtile coordinates in the this last argument. The coordinates of the subtiles of the atlas are:
So, if we use
we get:
-
The first two arguments specify the position of the tile we want to change. In my case, I change the tile at the position (5, 5) of the TileMap
-
The third argument is the index of the tile, as we have seen earlier, it’s 0 in my case.
-
The next 3 argumets are used for flipping the tile or/and transposing it. I left the default values because I don’t want to do any of these thing.
-
Finally, the last argument, selects the subtile of the atlas we want to place. In this case, the tile in the x position 6 and y position 0.
Other examples
We can try with other subtiles too: