Initial dragging prototype
This commit is contained in:
@@ -12,15 +12,19 @@ func _ready() -> void:
|
|||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
if draggable:
|
if draggable:
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("click"):
|
||||||
|
initial_pos = global_position
|
||||||
|
return
|
||||||
|
|
||||||
if Input.is_action_pressed("click", true):
|
if Input.is_action_pressed("click", true):
|
||||||
self.global_position = Vector2(get_global_mouse_position().x, self.global_position.y)
|
is_dragging.is_dragging = true
|
||||||
|
offset = global_position - get_global_mouse_position()
|
||||||
elif Input.is_action_just_released("click"):
|
global_position = Vector2(offset.x, initial_pos.y)
|
||||||
|
|
||||||
|
elif Input.is_action_just_released("click") && is_dragging.is_dragging:
|
||||||
is_dragging.is_dragging = false
|
is_dragging.is_dragging = false
|
||||||
var tween = get_tree().create_tween()
|
var tween = get_tree().create_tween()
|
||||||
|
tween.tween_property(self, "global_position", Vector2(get_global_mouse_position().x, initial_pos.y), 0.5).set_ease(Tween.EASE_OUT)
|
||||||
tween.tween_property(self, "global_position", Vector2(get_global_mouse_position().x, self.global_position.y), 0.5).set_ease(Tween.EASE_IN_OUT)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
@@ -29,3 +33,12 @@ func reset_draggable():
|
|||||||
if not is_dragging.is_dragging:
|
if not is_dragging.is_dragging:
|
||||||
is_dragging.is_dragging = false
|
is_dragging.is_dragging = false
|
||||||
draggable = false
|
draggable = false
|
||||||
|
|
||||||
|
|
||||||
|
func _on_mouse_exited() -> void:
|
||||||
|
reset_draggable()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_mouse_entered() -> void:
|
||||||
|
if not is_dragging.is_dragging:
|
||||||
|
draggable = true
|
||||||
|
|||||||
@@ -23,3 +23,6 @@ offset_top = 299.0
|
|||||||
offset_right = 455.0
|
offset_right = 455.0
|
||||||
offset_bottom = 299.0
|
offset_bottom = 299.0
|
||||||
script = ExtResource("2_mej84")
|
script = ExtResource("2_mej84")
|
||||||
|
|
||||||
|
[connection signal="mouse_entered" from="Sliding Box/EmptySpaceThing" to="Sliding Box/EmptySpaceThing" method="_on_mouse_entered"]
|
||||||
|
[connection signal="mouse_exited" from="Sliding Box/EmptySpaceThing" to="Sliding Box/EmptySpaceThing" method="_on_mouse_exited"]
|
||||||
|
|||||||
Reference in New Issue
Block a user