+2 votes

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?

in Engine by (17 points)

1 Answer

+2 votes
Best answer

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().tile_set_material(tile_id, ...)
        set_cell (x, y,  tile_id )

Not sure how to get cell's x and y though...

by (270 points)
selected by

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.