How to set a different image to an alternative tile in Godot 4?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dmitriy_shmilo

I’m editing a tileset In Godot 4, and I’d like to have different variants of the same tile being placed with a set_cell call. When I right-click a tile in the tileset editor and select “Create Alternative Tile”, it creates a tile with the same coordinates and source ID as the original, allows me to modify the original in certain ways and assign a probability to it. Very cool.

But simple rotation and modulation isn’t enough. I’d like to have a different region of the same texture assigned to an alternative tile and then call something like tile_map.set_cell(0, tile_coords, source_id, atlas_coords, randi() % alt_count) in my script, and have different versions of the tile being set. Any way of doing this while keeping the atlas_coords unchanged?

Thank you in advance.

The entire point of alternate tiles is to make use of the same atlas_coords in different ways, so I don’t think there is a way to do what you are asking.

If your goal is to place randomly selected tiles, there are other ways of doing that. The easiest way in the editor is to use a terrain set. I have not used the probability property through GDscript, but if you can do it with alternate tiles then you should be able to do it with Terrains in much the same way (using the same tile property even).

If you have not used Terrains before; I would recommend watching a short you-tube tutorial. Terrains are probably what you need.

Vadalken | 2023-07-06 12:19

Thank you, terrains are exactly what I needed. I was confused by the “alternative tile” name. Using set_cells_terrain_connect does what I need, and it even respects the probability property, which is very nifty.

dmitriy_shmilo | 2023-07-06 13:12