Skip to content

Instantly share code, notes, and snippets.

@Cowa
Last active October 17, 2021 00:59
Show Gist options
  • Save Cowa/fa28abdb1c5e5040dd7cdf99e882bbba to your computer and use it in GitHub Desktop.
Save Cowa/fa28abdb1c5e5040dd7cdf99e882bbba to your computer and use it in GitHub Desktop.
extends Control
var pressed = false
var offset = Vector2()
#######
func _gui_input(event):
if Input.is_action_just_pressed("left_click") and is_mouse_on_title():
pressed = true
offset = compute_offset()
elif Input.is_action_just_released("left_click"):
pressed = false
elif pressed and event is InputEventMouseMotion:
set_position(get_global_mouse_position() + offset)
#######
func is_mouse_on_title():
return $Title.get_global_rect().has_point(get_global_mouse_position())
func compute_offset():
return $Title.get_global_position() - get_global_mouse_position()
@Cowa
Copy link
Author

Cowa commented May 8, 2018

Scene structure:

window_draggable_scene

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment