This commit is contained in:
Torsten 2025-11-26 09:36:23 +01:00
parent a83692f9d6
commit cf2a9aaecf
2 changed files with 10 additions and 7 deletions

View file

@ -2,6 +2,8 @@ extends TileMapLayer
func _unhandled_input(event):
if event is InputEventMouseButton:
print("A click reached the ui layer")
pass
#print("A click reached the ui layer")
else:
print("Non UI-Layer event:", event)
pass
#print("Non UI-Layer event:", event)

View file

@ -7,16 +7,17 @@ func _ready():
func _input(event: InputEvent):
if %MapMenuContainer.visible==true: return
if event is InputEventMouseButton:
if event.pressed==false: return
var mouse_pos = get_viewport().get_mouse_position()
var mouse_pos = get_local_mouse_position()
#print("Local Mouse Position:", mouse_pos)
if mouse_pos.y < 0: return # outside of TileMap
var cell_pos = local_to_map(mouse_pos)
if mouse_pos.y < 33: return # outside of TileMap
var cell_pos = local_to_map(get_local_mouse_position())
var source_id = get_cell_source_id(cell_pos)
@ -27,11 +28,11 @@ func _input(event: InputEvent):
#Example: Place/erase tile on click
if event.button_index == MOUSE_BUTTON_LEFT:
print("Click left")
#print("Click left")
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")
#print("Click right")
set_cell(cell_pos, -1) # Erase tile