Hi,
A quick overview - I have a sprite that uses the Area2D signal _input_event
to detect it has been clicked and then highlight grid tiles on a tilemap. I want to then click one of those highlighted tiles and move the sprite there, which is where the problem arises.
I am retrieving the global mouse coordinates when a mouse depress is detected and then using world_to_map
to obtain the tilemap coordinates . Using _input(event)
on my sprite script I can obtain event.position
or event.global_position
and that works fine until I change the camera position at which point I get the wrong tilemap coordinates.
I have tried using get_global_mouse_position
and this works well even when the camera moves. However, using this method means that it will detect where the mouse last was rather than the click event, so if I move the mouse quickly after clicking it can give a false result. So my question is; what is the difference between using event.global_position
and get_global_mouse_position
in my case? Is there a better way to do this?
My scene structure is as follows:
Node2D (Root)
-Camera2D
-Tileset (parent)
-Sprite (child)
Thanks