diff --git a/MyObsidianVault/Knowledgebase/Godot/2D/TileMaps and TileMapLayers.md b/MyObsidianVault/Knowledgebase/Godot/2D/TileMaps and TileMapLayers.md new file mode 100644 index 0000000..d6f17b4 --- /dev/null +++ b/MyObsidianVault/Knowledgebase/Godot/2D/TileMaps and TileMapLayers.md @@ -0,0 +1,30 @@ +Hexmap Settings: +![[Pasted image 20250413094820.png]] + +GDScript on the layer: +```python +extends TileMapLayer + +func _unhandled_input(event): + if event is InputEventMouseButton: + var mouse_pos = get_local_mouse_position() + var cell_pos = local_to_map(mouse_pos) + print("Clicked cell: ", cell_pos) + + var source_id = get_cell_source_id(cell_pos) + print("source_id:", source_id) + + if source_id > -1: + print("Atlas coords:") + var atlas_coords = get_cell_atlas_coords(cell_pos) + print(atlas_coords) + + #Example: Place/erase tile on click + if event.button_index == MOUSE_BUTTON_LEFT: + pass + #set_cell(cell_pos, 51, Vector2i(6, 1)) # Place tile + elif event.button_index == MOUSE_BUTTON_RIGHT: + set_cell(cell_pos, -1) # Erase tile + +``` + diff --git a/MyObsidianVault/Pasted image 20250413094820.png b/MyObsidianVault/Pasted image 20250413094820.png new file mode 100644 index 0000000..999bab3 Binary files /dev/null and b/MyObsidianVault/Pasted image 20250413094820.png differ