Skip to content

Instantly share code, notes, and snippets.

@spkellydev
Last active July 6, 2024 22:49
Show Gist options
  • Save spkellydev/1c0632596832f722d47b1014ac576a13 to your computer and use it in GitHub Desktop.
Save spkellydev/1c0632596832f722d47b1014ac576a13 to your computer and use it in GitHub Desktop.
godot 4.1 tilemap updates not working as expected?
func create_warren(location : Vector2):
var local_pos = tile_map.local_to_map(location)
var tileset_source_id = 6
var atlas_coords = Vector2i(0, 0)
var buildings_layer = 5
# add building to tilemap
tile_map.set_cell(buildings_layer, local_pos, tileset_source_id, atlas_coords)
var ground_layer = 0
var building_layer = 5
var tile_data : TileData = tile_map.get_cell_tile_data(ground_layer, local_pos)
# set has_building for every tile the building touches
var i = -5
while i < 5:
var l = local_pos
l.x += i
print(str(l))
var next_tile_data : TileData = tile_map.get_cell_tile_data(ground_layer, l)
if next_tile_data:
tile_map.add_modulated_cell(l)
# trigger TileMap._tile_data_runtime_update
next_tile_data.set_custom_data(tile_has_building, true)
i += 1
extends TileMap
var modulated_cells : Dictionary
func add_modulated_cell(v : Vector2i):
modulated_cells[v] = Color.DARK_RED
func _ready():
pass
func _use_tile_data_runtime_update(layer, coords):
var r = modulated_cells.has(coords)
return r
func _tile_data_runtime_update(layer, coords, tile_data):
if layer == 1:
var color = modulated_cells.get(coords)
tile_data.modulate = color
force_update(0) # removes my layer 0 while also modulating somehow
print_debug(str(tile_data.get_custom_data("has_building"))) # returns false somehow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment