how to interact with a tile in tile-map?

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

like in RimWorld, player can mine, and cut tress, et, how can we do this in godot?
any one can give a example?
thanks!

:bust_in_silhouette: Reply From: Merlin1846

It is very simple to retrieve tile data and set data with a tile map.
And their are a few ways to do each.

RETRIEVE:

func getTIle(pos):
    $tileMap.get_cell(pos)
#pos must be a vector2

or

func getTIle(posX,posY):
    $tileMap.get_cellv(posX,posY)
#This one does not work off of a vector but rather off of the tileMaps grid

SET:

func getTIle(pos):
    $tileMap.set_cell(pos)
#pos must be a vector2

or

func getTIle(posX,posY):
    $tileMap.set_cellv(posX,posY)
#This one does not work off of a vector but rather off of the tileMaps grid.

You can also check out the documentation for the tile map.
docs.godotengine.org/en/stable/classes/class_tilemap.html
The methods section should help the most.

thanks for the answer.
i’m trying now.

can i ask, how can i add variables to a tile? or attach some variable to this tile.

like, some tile are Stones, then i can mine the Stone.

huahuapro | 2020-03-28 10:42

You can’t add variables to tiles but you can use the get cell function to see what type of tile it is and use that to determined whether or not it can be mined.

Merlin1846 | 2020-03-29 16:58