I am programming a moving-tile sequence, similar to Conway's Game of Life, but I am wanting to automate the layout to randomly have cells off or on at the ready. I am in Godot 3.5. My tileset only has one tile and the rest is just blank. I know there is a way to do this and I am drawing a blank on finding it. I know how to get an array of tiles (get_cells) and how to iterate through the array, I just can't seem to find how to set a cell's index in the tileSet through code in the docs.

  • SnapCracklins replied to this.
  • SnapCracklins Nevermind I found it. Remind yourself to not scroll so fast in documents. This is only for tileMap with two tiles but can be repurposed easily.

    The answer for those who need it:

    func _randomizer(): ## randomize tilemap at intro
    	for cell_position in get_used_cells():
    		randomize()
    		var _flip = randf()
    		if _flip > 0.5:
    			set_cell(cell_position.x,cell_position.y,1)
    		else:
    			set_cell(cell_position.x,cell_position.y,2)
    SnapCracklins changed the title to Populate tileMap tiles automatically in code .

    SnapCracklins Nevermind I found it. Remind yourself to not scroll so fast in documents. This is only for tileMap with two tiles but can be repurposed easily.

    The answer for those who need it:

    func _randomizer(): ## randomize tilemap at intro
    	for cell_position in get_used_cells():
    		randomize()
    		var _flip = randf()
    		if _flip > 0.5:
    			set_cell(cell_position.x,cell_position.y,1)
    		else:
    			set_cell(cell_position.x,cell_position.y,2)