You need to have a world state
.
I created a Node2D
scene with a TileSet
with a TileSet image. Mine has 12 tiles.
I set one tile every _process
randomly
extends Node2D
onready var tiles:TileMap = $TileMap
var world_width:int = 100
var world_height:int = 100
var world_state:PoolIntArray
func _ready():
world_state = PoolIntArray()
world_state.resize(world_width * world_height)
func _process(delta):
# Select a random cell
var x:int = randi() % world_width
var y:int = randi() % world_height
var food:int = randi() % 12
# Change world state
world_state[x + y * world_height] = food
tiles.set_cell(x, y, world_state[x + y * world_height])
Hope this answers your question.