Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lsgrandchamp |
Hey,
I am working on a small prototype that works with tilemaps. At a certain point, the player needs to drag and drop a button on the tilemap. The code is working fine on PC but not on mobile devices, where the correct position is always offset a little.
The button that will be dragged:
func get_drag_data(_position):
var preview = button.duplicate()
set_drag_preview(preview)
return self
The UI above the tilemap that will receive the drop:
func drop_data(position, _data):
EventHub.emit_signal("skill_dropped",position)
As I’ve said, the above code works on PC, but not on mobile devices, as I always need to touch a tad above the “correct” spot.
I’ve tried to get the global_position, but nothing has changed:
func drop_data(position, _data):
var global_touch_position = get_canvas_transform().xform_inv(position)
print(global_touch_position)
EventHub.emit_signal("skill_dropped",global_touch_position)
Edit: With more testing, I’ve found that the problem lies when the screen is stretched or loses the original aspect ratio, as can be seen in the images below:
Here the code works as intended and the touched position corresponds exactly with the selected tile:
But here I need to touch a bit higher than the right position to select the desired tile:
I need to get the touch position taking into account these screen stretches/aspects.
Any suggestions?
Thanks,
Lucas Sene