How to animate text?

Godot Version

v4.4.1.stable.mono.official [49a5bc7b6]

Question

How can I animate text? As in changing the .text property of a node rapidly to animate thing frame-by-frame. I tried to do it, and it does achieve the intended effect, but the text flash in and out.

This is not to be confused with revealing text using .visible_characters property.

I an wondering why it is flashing? What is your FPS?

I created a Node2D, added a Label child node and put a script on the Node2D of this:

extends Node2D

@onready var ANIMATED_LABEL: Label = $AnimatedLabel

const DEFAULT_TEXT: String = "______________________________"
const ANIMATED_CHAR: String = "@"

var char_position: int = 0
var current_text: String


func _ready() -> void:
	ANIMATED_LABEL.text = DEFAULT_TEXT


func _process(_delta: float) -> void:
	current_text = DEFAULT_TEXT
	current_text[char_position] = ANIMATED_CHAR
	ANIMATED_LABEL.text = current_text
	char_position += 1
	if char_position > current_text.length() - 1:
		char_position = 0

The ‘@’ character moves pretty smoothly across the string without flashing. Is that the type of animation you meant?

1 Like

Huh, it suddenly works now. I didn’t try your specific solution, but my code now works fine.

I’m not sure what I had done wrong tbh. Maybe I will revisit this and figure out why later. Thank you for your help!

(I had this issue in my project 3 weeks ago and only get around to it now. Safe to say it will be a mystery for a good while :stuck_out_tongue:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.