GodotComponentTest/components/ClickableComponent.gd

29 lines
568 B
GDScript
Raw Normal View History

2022-08-17 00:50:30 +02:00
class_name ClickableComponent
extends Node
signal clicked()
export var collision_size = Vector2(1, 1)
onready var collision_shape = $Area2D
2022-08-19 18:48:54 +02:00
var is_mouseover = false
2022-08-17 00:50:30 +02:00
# Called when the node enters the scene tree for the first time.
func _ready():
collision_shape.scale = collision_size
2022-08-19 18:48:54 +02:00
func _input(event):
if event is InputEventMouseButton and event.pressed and is_mouseover:
2022-08-17 00:50:30 +02:00
emit_signal ("clicked")
2022-08-19 18:48:54 +02:00
get_tree().get_root().set_input_as_handled()
func _on_Area2D_mouse_entered():
is_mouseover = true
func _on_Area2D_mouse_exited():
is_mouseover = false