Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | samjmiller |
Hello friends!
I want to have my dialogue boxes animate when they pop up, so I tweened ‘rect_size’ to go from Vector2(0, 0) to the full size. And it works great!
Once.
After the first time I talk to an NPC, every subsequent interaction the dialogue box pops up fully formed with no tweening. Like once it’s been used, it’s not resetting, or SOMETHING. Everything else seems to work fine.
(Possibly-related question - I would love to be able to tween OUT the box, when the player closes out of the dialogue. I tried adding a separate tween for closing but it created a whole new set of problems)
Really appreciate any ideas y’all might have about how to get this working more than once. See below for my code. The popup contains three ColorRects on top of each other to give a frame effect, that’s why it seems to be called three times on _ready.
extends Popup
var npc_name setget name_set
var dialogue setget dialogue_set
var answers setget answers_set
var npc
onready var effect = get_node("Open")
onready var sprite = get_node("ColorRect")
onready var sprite2 = get_node("ColorRect2")
onready var sprite3 = get_node("ColorRect3")
func _ready():
set_process_input(false)
effect.interpolate_property(sprite, 'rect_size', Vector2(0, 0), Vector2(300, 95), 0.3,
Tween.TRANS_SINE, Tween.EASE_OUT)
effect.interpolate_property(sprite2, 'rect_size', Vector2(0, 0), Vector2(304, 99), 0.3,
Tween.TRANS_SINE, Tween.EASE_OUT)
effect.interpolate_property(sprite3, 'rect_size', Vector2(0, 0), Vector2(308, 103), 0.3,
Tween.TRANS_SINE, Tween.EASE_OUT)
effect.interpolate_property(sprite, 'modulate',
Color(0,0,0,0), Color(1,1,1,1), 0.3,
Tween.TRANS_SINE, Tween.EASE_OUT)
func name_set(new_value):
npc_name = new_value
$ColorRect/NPCName.text = new_value
func dialogue_set(new_value):
dialogue = new_value
$ColorRect/Dialogue.text = new_value
func answers_set(new_value):
answers = new_value
$ColorRect/Answers.text = new_value
func open():
get_tree().paused = true
effect.start()
popup()
$AnimationPlayer.playback_speed = 30.0 / dialogue.length()
$AnimationPlayer.play("ShowDialogue")
func _on_Open_tween_completed(object, key):
pass
func _input(event):
if event is InputEventKey:
if event.scancode == KEY_A:
set_process_input(false)
npc.talk("A")
elif event.scancode == KEY_B:
set_process_input(false)
npc.talk("B")
func close():
get_tree().paused = false
hide()
func _on_AnimationPlayer_animation_finished(anim_name):
set_process_input(true)