Can you modify a single instance of a tile in a tilemap?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mythicsmt
:warning: Old Version Published before Godot 3 was released.

Is it possible to have different instances of the same tile in a tilemap use different properties such as modulate color?

Imagine having a tile that is nothing more than a 16x16 pixel white square, but you want to tint it a different color on the tilemap based on it’s X or Y value within the map. Is this possible or would you need a different tile for every potential tint color?

:bust_in_silhouette: Reply From: Artium Nihamkin

If you have all the possible tint colors in the TileSet already, than you can use the TileMaps get_used_cells function to retrieve and the used cells and set_cell to set the tile you want from the TileSet.

You can also create the tint colors dynamically, using TileSets create_tile method

Example (TileMap’s script):

extends TileMap

func _ready():

    for c in get_used_cells():
        x, y = ...
        tile_id = 100 + x + 1000*y #probably should not conflict with existing tiles
        get_tileset().create_tile(tile_id)
        get_tileset().tile_set_material(tile_id, ...)
        set_cell (x, y,  tile_id )

Not sure how to get cell’s x and y though…

To solve the x,y issue, you can iterate over every possible cell (screen height/cell height, over screen width/cell width) and use get_cell to get the tile at that location. That way you will have both the id of the cell and it’s location on the grid.

Artium Nihamkin | 2017-12-31 07:34