![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Robster |
Hi all,
I have a tilemap
and when I click on it I want it to “paint”.
This is working, but there is an offset. The tiles paint beside and lower down from the mouse, not straight under it. Then, as the camera moves, the offset grows. Which makes me think the event.position
is reporting incorrectly to the world_to_map
due to some local space / world space issue. My code is below. What am I doing wrong? Thank you.
func _input(event):
if globals.activity == "dig":
var button = event.get_button_mask()
# we do this so we can click and drag
if (button == 1):
var tile_pos = get_node("/root/GameLevel/TileMap").world_to_map(event.position - Vector2(get_node("/root/GameLevel/Camera2D").get_h_offset(), get_node("/root/GameLevel/Camera2D").get_v_offset()-10))
print(tile_pos)
var name = get_node("/root/GameLevel/TileMap").tile_set.tile_get_name(28) # tile 28 is the colour in tile
get_node("/root/GameLevel/TileMap").set_cellv(tile_pos, get_node("/root/GameLevel/TileMap").tile_set.find_tile_by_name(name))
get_node("/root/GameLevel/TileMap").update_dirty_quadrants()