mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-09 19:04:36 +01:00
Example scene with some playing cards
This commit is contained in:
parent
41e14be5dd
commit
ddc71ed4ed
3 changed files with 61 additions and 0 deletions
21
card.gd
Normal file
21
card.gd
Normal file
|
@ -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
|
27
card.tscn
Normal file
27
card.tscn
Normal file
|
@ -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"]
|
13
cardgame.tscn
Normal file
13
cardgame.tscn
Normal file
|
@ -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 )
|
Loading…
Reference in a new issue