add clickable area to token scene
emit a signal when a click is registered
This commit is contained in:
@@ -22,6 +22,11 @@ activate={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
select={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
|
||||
8
token.gd
8
token.gd
@@ -1,5 +1,7 @@
|
||||
extends Node2D
|
||||
|
||||
signal token_clicked
|
||||
|
||||
enum token_type {TYPE_1, TYPE_2, TYPE_3, TYPE_4}
|
||||
|
||||
var type: token_type = token_type.TYPE_1
|
||||
@@ -25,3 +27,9 @@ func set_type(type: token_type):
|
||||
|
||||
func set_debug_label(text: String):
|
||||
debug_label.text = text
|
||||
|
||||
|
||||
func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
# emit event up to parent on click
|
||||
if Input.is_action_just_pressed("select"):
|
||||
token_clicked.emit()
|
||||
|
||||
13
token.tscn
13
token.tscn
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b50otusq306jl"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://b50otusq306jl"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cy18iue2caocn" path="res://token.gd" id="1_0ucay"]
|
||||
[ext_resource type="Texture2D" uid="uid://cqtw7t2uag6f8" path="res://icon.svg" id="1_bd72f"]
|
||||
@@ -10,6 +10,9 @@ outline_color = Color(0, 0, 0, 1)
|
||||
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_bd72f"]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0ucay"]
|
||||
size = Vector2(51, 51)
|
||||
|
||||
[node name="Token" type="Node2D"]
|
||||
script = ExtResource("1_0ucay")
|
||||
|
||||
@@ -33,3 +36,11 @@ polygon = PackedVector2Array(0, 0, 40, 0, 40, 40, 0, 40)
|
||||
scale = Vector2(0.4, 0.4)
|
||||
texture = ExtResource("1_bd72f")
|
||||
centered = false
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(26, 25.5)
|
||||
shape = SubResource("RectangleShape2D_0ucay")
|
||||
|
||||
[connection signal="input_event" from="Area2D" to="." method="_on_area_2d_input_event"]
|
||||
|
||||
Reference in New Issue
Block a user