Bugfix: Use actual atlas source id instead of a fixed static integer value

This commit is contained in:
Torsten 2025-11-05 05:29:07 +01:00
parent 0ada26f6a1
commit ff49c10c8f

View file

@ -5,6 +5,7 @@ signal hex_clicked(cell_pos:Vector2, atlas_coords:Vector2)
func _ready():
print("TileMapLayer is alive")
func _input(event: InputEvent):
#print("Unhandled input")
if event is InputEventMouseButton:
@ -22,9 +23,8 @@ func _input(event: InputEvent):
#Example: Place/erase tile on click
if event.button_index == MOUSE_BUTTON_LEFT:
print("Click left")
#pass
#set_cell(cell_pos, 51, Vector2i(6, 1)) # Place tile
set_cell(cell_pos, 0, Vector2i(1, 2)) # Place tile
var atlas_source_id = self.tile_set.get_source_id(0) # source id of first atlas in TileMapLayer
set_cell(cell_pos, atlas_source_id, Vector2i(1, 2)) # Place tile
elif event.button_index == MOUSE_BUTTON_RIGHT:
print("Click right")
set_cell(cell_pos, -1) # Erase tile