#How can I play a sound for each visible letter?

5 messages · Page 1 of 1 (latest)

trim prairie
#

Hey there! The solution to this is probably quite simple, and maybe I'm on the right track, but I can't seem to understand where I'm going wrong.

I have this tween setup so that the characters gradually show up on screen. I thought I could use a for loop which looked at text1.visible_characters and play a sound each time it updated but when I tried, I got nothing. I'm sure I'm missing something simple, but it's driving me crazy.

Any help would be appreciated!

tween = create_tween().set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_OUT)
tween.tween_property(text1, "visible_characters", char_count1, 2)```
fervent oar
#

You can add your code as text for readability.

https://docs.godotengine.org/en/stable/classes/class_tween.html

I see no start

tween.start()
trim prairie
#

hey there, i've added the code

the tween works and each letter is printed one by one, i was just wondering if there was a way to also associate each letter appearing with a sound playing, kind of like old school games/some indie games

trim prairie
#

I'm slowly figuring it out. I figure I need to compare the length of the string against the visible characters like so, I just need to figure out how to make the sound only play once now, rather than continuously

trim prairie
#

I found a solution! It was simple, I just overcomplicated it as usual. What I did was, I made a script on the RichText node and gave it a child with the sound I wanted to play, and I wrote this code:

extends RichTextLabel

var counter: int = 0
onready var keyboard = $keyboard

func play_key():
    if visible_characters > counter:
        counter += 1
        keyboard.play()
    
func _physics_process(delta):
    play_key()