1
0
Fork 0
mirror of https://github.com/tonytins/dressupzack synced 2025-06-25 08:04:43 -04:00

Advanced drag and drop system finished

This commit is contained in:
Tony Bark 2023-12-09 20:43:42 -05:00
parent ed75c25fef
commit 9ff5c5aae3
6 changed files with 28 additions and 9 deletions

View file

@ -2,6 +2,8 @@
# See the LICENSE file in the project root for more information.
extends Node2D
@export var group: String = "dropable"
var is_draggable = false
var is_inside_dropable = false
var body_ref
@ -11,19 +13,31 @@ var offset: Vector2
func _process(delta):
if is_draggable:
if Input.is_action_just_pressed("click"):
offset = get_global_mouse_position() - global_position
offset = global_position - get_global_mouse_position()
Global.is_dragging = true
if Input.is_action_pressed("click"):
global_position = get_global_mouse_position() - offset
elif Input.is_action_just_released("click"):
Global.is_dragging = false
var tween = get_tree().create_tween()
if is_inside_dropable:
tween.tween_property(self, "position", body_ref.position, 0.2).set_ease(Tween.EASE_OUT)
else:
tween.tween_property(self, "global_position", body_ref.position, 0.2).set_ease(Tween.EASE_OUT)
func _on_area_2d_body_entered(body):
if body.is_in_group('dropable'):
if body.is_in_group(group):
is_inside_dropable = true
body.modulate = Color(Color.REBECCA_PURPLE, 1)
scale = Vector2(1.05, 1.05)
body_ref = body
func _on_area_2d_body_exited(body:StaticBody2D):
if body.is_in_group('dropable'):
if body.is_in_group(group):
is_inside_dropable = false
body.modulate = Color(Color.MEDIUM_PURPLE, .7)
scale = Vector2(1.05, 1.05)