29 lines
568 B
GDScript
29 lines
568 B
GDScript
class_name ClickableComponent
|
|
extends Node
|
|
|
|
signal clicked()
|
|
|
|
export var collision_size = Vector2(1, 1)
|
|
|
|
onready var collision_shape = $Area2D
|
|
|
|
var is_mouseover = false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
collision_shape.scale = collision_size
|
|
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseButton and event.pressed and is_mouseover:
|
|
emit_signal ("clicked")
|
|
get_tree().get_root().set_input_as_handled()
|
|
|
|
|
|
func _on_Area2D_mouse_entered():
|
|
is_mouseover = true
|
|
|
|
|
|
func _on_Area2D_mouse_exited():
|
|
is_mouseover = false
|