Hello everyone! How I can use the fill on tilemap with code?

Godot Version

Godot Engine 4.2.1

Question

How I can use the fill with code? It is like set_cell
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅
I want to fill a white islands, because I vant to separate their on continents

Although I have no idea how the code is, I assume it would be the following:

  • Loop through each used cell in the tilemap
  • Check if the cell is of ID = white island
  • cell.modulate = Color.whateveryouwant

The code could be something like this

for tile in tilemap.get_used_cells(0): # I assume the cells are on layer0
	var tiledata = tilemap.get_cell_tile_data(0, tile)
	if tiledata == # however you distinguished the white islands
		tiledata.modulate = Color.YELLOW # or something
1 Like

I don’t understood β€œtiledata==”. I checked, if tile is land, then simply set a white color

if get_cell_atlas_coords(0, tile_position) in list_land_tiles:
	list_continens_tiles.append(tile_position)
	set_cell(4, tile_position, 2, Vector2i.ZERO)

Does this do what you want it to do?

if get_cell_atlas_coords(0, tile_position) in list_land_tiles:
	list_continens_tiles.append(tile_position)
	set_cell(4, tile_position, 2, Vector2i.ZERO)

	var cell = get_cell_tile_data(4, tile_position)
	cell.modulate = Color.WHITE
1 Like

Thank you for your help, but i get
(cell.modulate = Color.YELLOW)

I understood how do it

var t = 1
	for tile in list_continens_tiles:
		if get_cell_atlas_coords(4, tile) == Vector2i(0, 0):
			fill_continents(tile, Vector2i(t, 0))
			t += 1

func fill_continents(pos : Vector2i, colot_tile : Vector2i):
	var stack = [pos]
	var visited = []
	while stack.size() > 0:
		var position = stack.pop_back()
		# ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡΠ΅ΠΌ, Ссли Ρ‚Π°ΠΉΠ» ΡƒΠΆΠ΅ Π±Ρ‹Π» посСщСн
		if position in visited:
			continue
		# ЗамСняСм Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ Ρ‚Π°ΠΉΠ» Π½Π° Π½ΠΎΠ²Ρ‹ΠΉ
		set_cell(4, position, 2, colot_tile)
		# ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ сосСдниС Ρ‚Π°ΠΉΠ»Ρ‹
		for offset in list_vectors:
			var neighbor_position = position + offset
			if get_cell_atlas_coords(4, neighbor_position) == Vector2i(0, 0):
				stack.append(neighbor_position)
				

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.