Godot - Displaying Text One Character at a Time in a RichTextLabel
The number of characters in the text is obtained using `length()
` and a loop is implemented.
The process of adding one character at a time using `add_text()
` is executed at a specified interval using `await`.
In GDScript, you can use `fill()
` to replace all the values in an array with a specified value.
This changes existing values or null to the specified value.
# Create a new RichTextLabel
add_child(label)
label.global_position = Vector2(0, 0)
label.size = Vector2(200,200)
var label = RichTextLabel.new()
# Text to display
var label_text = "Make text come up one character at a time."
# Loop through the number of characters
for i in label_text.length():
# Execute the process at a specified interval using await
await get_tree().create_timer(0.1).timeout
# Add one character from the text
add_text(label_text[i])
If BBCode is enabled and you want to add tagged text, use `append_text()
`.
# Create a new RichTextLabel
var label = RichTextLabel.new()
# Text to display
var label_text = "Make text come up one character at a time."
# Loop through the number of characters
for i in label_text.length():
# Execute the process at a specified interval using await
await get_tree().create_timer(0.1).timeout
# Add one character from the text
append_text(label_text[i])
TitleGodot - Displaying Text One Character at a Time in a RichTextLabel
CategoryGodot
Created
Update
AuthorYousuke.U