Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | indy2005 |
I have Player1 with a Tween. The parent node is connected to the tween_completed signal via the UI.
I have Player2 which I need to react to the tween in Player1 completing.
I had thought I could simply connect Player2 to tween_completed on Player1, but this doens’t work. Instead I have to emit a separate signal from within Player1, in the on_tween_completed function, which I then capture. I would have thought on_tween_completed was a general signal which could be caught by any node in the scene that was interested.
i.e. This doesnt work:
Player1
extends Node2D
export var index:int = 0
onready var tween:Tween = $Tween
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
signal hide_players
# Called when the node enters the scene tree for the first time.
func _ready():
if index == 1:
tween.interpolate_property(self, "scale", null, Vector2(2.0,2.0), 4,Tween.TRANS_EXPO,Tween.EASE_IN)
tween.start()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Tween_tween_completed(object, key):
self.visible = false
Player2
# Called when the node enters the scene tree for the first time.
func _ready():
var player = get_node("/root/Game/Player1")
player.connect("tween_completed", self, "_vanish")
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _vanish():
self.visible = false
But this arrangment does work, where I emit a fresh signal within Player1.
Player1
func _on_Tween_tween_completed(object, key):
self.visible = false
emit_signal("hide_players")
Player2
player.connect("hide_players", self, "_vanish")