#Creating smooth draggable windows

1 messages · Page 1 of 1 (latest)

cursive root
#

Hi all!
I'm currently working on creating an OS-style interface with seperate draggable windows.
Currently I have this implemented using an Area2D for the top bar and a sprite for the general window, however the window is struggling to keep up with quicker mouse movements.
Is there any way to make this responsive or just a better way to implement this in general? Thanks!

#

Relevant code snippet:
Offset is to make the drag move to the top bar because otherwise it moves to the center of the window.
mouse_hover is just a boolean check if the mouse is on the top bar.

    if Input.is_action_pressed("left_click") and mouse_hover:
        global_position = floor(get_global_mouse_position() + Vector2(0, 44)) # Offset to center on top bar
        

func _on_mouse_entered() -> void:
    mouse_hover = true


func _on_mouse_exited() -> void:
    mouse_hover = false
#

Scene setup (Vbox container is for the contents of the window so less relevant with this issue)

cursive root
#

Fixed this by adapting from checking whether the mouse is within the Area2D to instead registering if the mouse is still clicked.

Stumbled into the following tutorial and adapted for my use case and Godot 4:
https://www.youtube.com/watch?v=iSpWZzL2i1o

Timestamps

Dragging: 0:22
Dropping: 2:30
Rest zones: 3:06

Hooking it up: 4:35
Rotation: 6:42
Examples 8:02
Cpp bonus: 8:35

A simple and elegant approach for dragging and dropping sprites in Godot using a variety of built in functions.

All the code is availiable on my Github here: https://github.com/bramreth/godot_tutorial_content/tree/maste...

▶ Play video