Can I draw/spawn tiles from a tileset?

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

I have a tile map that has a tile set that haves tiles, I want my gdscript to spawn/draw tiles in the scene, is it possible to do this?

The only thing I could do from the docs is to get and modify the tile properties but I have not been able to draw it a desired coordinate, is creating a scene for each tile the way to go about this?

:bust_in_silhouette: Reply From: njamster

You can use set_cellv to set the tile for a certain cell of the TileMap:

func _ready():
    var cell = Vector2(2, 2)
    var tile_id = 3
    $TileMap.set_cellv(cell, tile_id)

Cells are zero-indexed, so this will set the third cell that’s third from the left and third from the top. Same for tile-ids, so it will use the fourth tile in your tileset. Using a tile-id of -1 will will reset the cell to using no tile at all.