- Edited
Hello.
I have a main scene "GameScreen" that under certain conditions (on timer or when certain functions are called) emits two signals: declare_day and declare_night respectively.
I want to instance SunPlant scenes that play different animations (flower opening, flower open, flower closing - which is just opening backwards, flower closed) based on whether it's day, night, or whether it has changed.
And I just can't figure out how to make the instance connect to the GameScreen when it's spawned...
extends Node2D
var last_anim = null
func _ready() -> void:
pass
func _process(delta: float) -> void:
pass
func _on_game_screen_declare_day() -> void:
$AnimatedSprite2D.play("sun_plant_opening")
last_anim = "sun_plant_opening"
func _on_game_screen_declare_night() -> void:
$AnimatedSprite2D.play_backwards("sun_plant_opening")
last_anim = "sun_plant_closing"
func _on_animated_sprite_2d_animation_finished() -> void:
if last_anim == "sun_plant_opening":
$AnimatedSprite2D.play("sun_plant_open")
elif last_anim == "sun_plant_closing":
$AnimatedSprite2D.play("sun_plant_closed")
Could someone please help me? Connecting signals via the editor when both nodes are on the scene is very easy but I just can't figure out how to make it work through code on instances when the instance should be a passive listener.
I tried looking at several tutorials, text or video, but couldn't transfer the specific examples to my specific example.