From ddc71ed4edf779d139499284adb5a555785c1422 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 13 Oct 2020 13:04:12 +0200 Subject: [PATCH] Example scene with some playing cards --- card.gd | 21 +++++++++++++++++++++ card.tscn | 27 +++++++++++++++++++++++++++ cardgame.tscn | 13 +++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 card.gd create mode 100644 card.tscn create mode 100644 cardgame.tscn diff --git a/card.gd b/card.gd new file mode 100644 index 0000000..4cca88f --- /dev/null +++ b/card.gd @@ -0,0 +1,21 @@ +extends Node2D + +var dragged = false +var drag_offset + +func _ready(): + set_process_unhandled_input(true) + +func _process(delta): + if dragged: + var mousepos = get_viewport().get_mouse_position() + position = mousepos - drag_offset + +func _unhandled_input(event): + print("input event!") + if event is InputEventMouseButton: + if event.button_index == BUTTON_LEFT and event.pressed: + dragged = true + drag_offset = get_viewport().get_mouse_position() - global_position + elif event.button_index == BUTTON_LEFT and !event.pressed: + dragged = false diff --git a/card.tscn b/card.tscn new file mode 100644 index 0000000..efb9377 --- /dev/null +++ b/card.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://card.gd" type="Script" id=1] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 105.74, 143.46 ) + +[node name="Card" type="Node2D"] +script = ExtResource( 1 ) + +[node name="KinematicBody2D" type="KinematicBody2D" parent="."] +position = Vector2( 536.216, 510.56 ) +input_pickable = true + +[node name="Panel" type="Panel" parent="KinematicBody2D"] +visible = false +margin_left = -104.0 +margin_top = -143.0 +margin_right = 106.0 +margin_bottom = 141.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="CollisionShape2D" type="CollisionShape2D" parent="KinematicBody2D"] +shape = SubResource( 1 ) +[connection signal="input_event" from="KinematicBody2D" to="." method="_input_event"] diff --git a/cardgame.tscn b/cardgame.tscn new file mode 100644 index 0000000..c2e9160 --- /dev/null +++ b/cardgame.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://card.tscn" type="PackedScene" id=1] + +[node name="Cardgame" type="Node2D"] + +[node name="Card" parent="." instance=ExtResource( 1 )] + +[node name="Card2" parent="." instance=ExtResource( 1 )] +position = Vector2( 118.019, -91.0798 ) + +[node name="Card3" parent="." instance=ExtResource( 1 )] +position = Vector2( 474.641, 118.019 )