I’m starting a small project in which I want to randomly generate a map. I’m taking it slow and have managed to upload the tileset to the atlas (where each tile has its own position). The question is, how do I configure the tiles so I can reference them in the code?
It depends one what you want to be able to do with them. Referencing tiles is generally pretty clunky in my opinion and there is no way to configure the tileset to provide an easy way to reference them.
If you need to set a cell to a tile from the tileset, use TileMapLayer.set_cell using the ID of the tile’s atlas and the tile’s coordinates within that atlas.
You can check if two tiles are the same by getting their source IDs and atlas coordinates and comparing them:
func compare_tiles(tilemap: TileMapLayer, coords_1: Vector2i, coords_2: Vector2i) -> bool:
var source_id_1 := tilemap.get_cell_source_id(coords_1)
var source_id_2 := tilemap.get_cell_source_id(coords_2)
if source_id_1 != source_id_2:
return false
var atlas_coords_1 := tilemap.get_cell_atlas_coords(coords_1)
var atlas_coords_2 := tilemap.get_cell_atlas_coords(coords_2)
return atlas_coords_1 == atlas_coords_2
There are also some good tutorials out there so you don’t have to start from scratch. I think this one was pretty good: Procedural Generation with Tilemaps.