Are any dynamic elements should be in tilemap?

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

Hi
I’ve just started learn godot and i trying to make side scroll platformer. I set up yellow tile and i want to replace this tile with green one, when player collide with this tile. How i can do that? Or maybe i should use tilemap only for static, non-interactive elements, and make interactive elements with sprites or something?

:bust_in_silhouette: Reply From: Zylann

You can modify a TileMap in the game the same way you modify it in the editor.
You have to use the set_cell function: TileMap — Godot Engine (stable) documentation in English

The function expects a tile index, but you can also use the tile name by looking into the TileSet:

var tile_index = tilemap.get_tileset().find_tile_by_name("your_tile_name")
tilemap.set_cell(x, y, tile_index)
:bust_in_silhouette: Reply From: eons

The ideal is to use tilemaps for static tiles only, if are used to make tilemaps with some advanced editor like Tiled, then you may also be used to parse the tilemap and spawn game elements replacing special tiles (animated, triggers, etc.).

Using the corresponding nodes for interactive objects will make the level design a lot more flexible and easier to update than depending on tiles.

That said, you can do many things with tiles, working like old times using the tilemap as if it were an array, it has some functions to translate coordinates, getting used cells and many other things for tile-dependant designs.
Also parse the tilemap on runtime to replace tiles with other nodes.