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

Advanced drag and drop

More precise drag and drop. Still has a few bugs, but most of the base is there.

- Removed translations.
- Cleaned up README
This commit is contained in:
Tony Bark 2023-12-07 21:45:26 -05:00
parent 805cbe2738
commit 2bc37e1100
18 changed files with 173 additions and 58 deletions

5
scripts/global.gd Normal file
View file

@ -0,0 +1,5 @@
# This project is licensed under the GPL-3.0 license.
# See the LICENSE file in the project root for more information.
extends Node
var is_dragging = false

41
scripts/object.gd Normal file
View file

@ -0,0 +1,41 @@
# This project is licensed under the GPL-3.0 license.
# See the LICENSE file in the project root for more information.
extends Node2D
var is_draggable = false
var is_inside_dropable = false
var body_ref
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if is_draggable:
if Input.is_action_just_pressed("click"):
global_position = get_global_mouse_position()
elif Input.is_action_just_released("click"):
is_draggable = false
var tween = get_tree().create_tween()
if is_inside_dropable:
tween.tween_property(self,"postion",body_ref.position,0.2).set_ease(Tween.EASE_OUT)
else:
tween.tween_property(self,"global_postion",body_ref.position,0.2).set_ease(Tween.EASE_OUT)
func _on_area_2d_body_entered(body):
if body.is_in_group('dropable'):
is_inside_dropable = true
scale = Vector2(1.05, 1.05)
func _on_area_2d_body_exited(body:StaticBody2D):
if body.is_in_group('dropable'):
is_inside_dropable = false
scale = Vector2(1.05, 1.05)
func _on_area_2d_mouse_entered():
if not Global.is_dragging:
is_draggable = true
scale = Vector2(1.05, 1.05)
func _on_area_2d_mouse_exited():
if not Global.is_dragging:
is_draggable = false
scale = Vector2(1, 1)

12
scripts/platform.gd Normal file
View file

@ -0,0 +1,12 @@
# This project is licensed under the GPL-3.0 license.
# See the LICENSE file in the project root for more information.
extends StaticBody2D
func _ready():
modulate = Color(Color.MEDIUM_PURPLE, 0.7)
func _process(delta):
if Global.is_dragging:
visible = true
else:
visible = false