35 lines
1 KiB (Stored with Git LFS)
GDScript3
35 lines
1 KiB (Stored with Git LFS)
GDScript3
extends Panel
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
var snap_position = Vector2(0,0)
|
|
var snap_velocity = 800
|
|
var is_dragged = false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
snap_position = rect_position
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
if not rect_position == snap_position and not is_dragged:
|
|
if (snap_position - rect_position).length() < 10:
|
|
rect_position = snap_position
|
|
else:
|
|
var deltapos_angle = (snap_position - rect_position).angle()
|
|
rect_position += Vector2(
|
|
snap_velocity * cos(deltapos_angle),
|
|
snap_velocity * sin(deltapos_angle)
|
|
) * delta
|
|
|
|
|
|
func _on_Card_gui_input(event):
|
|
if event is InputEventScreenDrag:
|
|
is_dragged = true;
|
|
rect_position += event.relative
|
|
elif Input.is_action_just_released("click"):
|
|
is_dragged = false
|