necra-prototypes/selectable.gd
Antonio Dell'Annunziata 95be5ae355
All checks were successful
/ test (push) Successful in 1s
Add selectable on hover effect
2025-03-05 06:35:47 +01:00

29 lines
981 B
GDScript

class_name Selectable
extends Area2D
var selection_sprite: Sprite2D
func _ready():
if selection_sprite: return
var parent_sprite = get_parent() as Sprite2D
selection_sprite = Sprite2D.new()
selection_sprite.texture = parent_sprite.texture.duplicate(true)
var scale_x = ((selection_sprite.texture.get_size().x + 10) / selection_sprite.texture.get_size().x)
var scale_y = ((selection_sprite.texture.get_size().y + 10) / selection_sprite.texture.get_size().y)
selection_sprite.scale = Vector2(scale_x,scale_y)
selection_sprite.show_behind_parent = true
selection_sprite.modulate = Color.BLACK
selection_sprite.visible = false
parent_sprite.call_deferred("add_child", selection_sprite)
parent_sprite.call_deferred("move_child", selection_sprite, 0)
func _on_mouse_entered():
_show_selection_outline()
func _on_mouse_exited():
_hide_selection_outline()
func _show_selection_outline():
selection_sprite.show()
func _hide_selection_outline():
selection_sprite.hide()