30 lines
583 B
GDScript
30 lines
583 B
GDScript
extends StaticBody2D
|
|
|
|
signal changed(open)
|
|
|
|
func set_open(open: bool):
|
|
if open:
|
|
$Sprite.play("open")
|
|
else:
|
|
$Sprite.play("close")
|
|
|
|
func _animation_finished():
|
|
if $Sprite.animation == "open":
|
|
# Disable collider
|
|
collision_layer = 16
|
|
collision_mask = 16
|
|
# Start timer for auto-close
|
|
$Timer.start()
|
|
else:
|
|
# Enable collider
|
|
collision_mask = 1
|
|
collision_layer = 1
|
|
|
|
func _input_event(viewport, event, shape_idx):
|
|
if event is InputEventMouseButton and event.pressed:
|
|
set_open($Sprite.animation == "close")
|
|
|
|
|
|
|
|
func _close_timer_triggered():
|
|
$Sprite.play("close")
|