How to randomly replace a subtile in Atlas tile-set by code

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

Hi, I trying to have some subtile in an Atlas tile set to be randomly replace by other subtile to create variation of texture. In code, how would I be able to do that, Thank you.

For example, I have 9 subtile in 1 Atlas tile set. How do I replace subtile number 2 by number 8 by code? Thank you.

:bust_in_silhouette: Reply From: exuin

Confusingly, the atlas tiles also use the features called “autotile.”

So it would be

TileMap.set_cell(x, y, TileMap.get_cell(x, y), false, false, false, 8)
TileMap.set_cell(x, y, TileMap.get_cell(x, y), false, false, false, 8)

Thanks for answering my question. so in the code set_cell(x, y), are the x and y the vector2 position of whatever tile used in the Tile-map scene? or it is the position of subtile in the Atlas texture?

I tried to use set_cell before, but from my understanding the set_cell(x, y, TileId) refers to the vector2 position of the tile used in the TileMap scene rather than the position of subtile in the Atlas.

For example, I tried to use TileMap.set_cell(1,0, TileID), and instead of replacing the subtile in (1, 0) on the Atlas texture with new tile of TileID. The code replace the tile used in the TileMap scene with TileID.

Idleman | 2022-03-09 00:33

Yeah, x and y are the coordinates of the tile in the tilemap.

exuin | 2022-03-09 03:42