I'm working on a small project and I need to disable the border to achieve the desired effect. However, this makes the game screen unmovable. So I wrote the following code to enable dragging the screen with mouse:
func _input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
dragging = true
mouse_in_pos = get_viewport().get_mouse_position()
else:
dragging = false
if event is InputEventMouseMotion and dragging:
mouse_pos = get_viewport().get_mouse_position()
get_tree().get_root().position = Vector2(get_tree().get_root().position) + mouse_pos - mouse_in_pos
The game can now detect mouse drag behavior, but the screen still cannot be dragged. How can I improve this code?