Skip to content

Instantly share code, notes, and snippets.

@EricEzaM
Last active August 26, 2024 22:02
Show Gist options
  • Save EricEzaM/c8d3cd4e3f031df1191dfe45b183b69f to your computer and use it in GitHub Desktop.
Save EricEzaM/c8d3cd4e3f031df1191dfe45b183b69f to your computer and use it in GitHub Desktop.
A label which progressively shows characters, as if someone was typing.
#########################################################
# Basic Version
#########################################################
extends Label
var timer: Timer
func _ready():
timer = Timer.new()
timer.wait_time = 0.1
timer.autostart = true
timer.connect("timeout", self, "timer_tick")
visible_characters = 0
add_child(timer)
timer.start()
func timer_tick():
visible_characters += 1
if visible_characters >= text.length():
visible_characters = -1
timer.stop()
#########################################################
# More advanced version with iterating messages
#########################################################
extends Label
var messages = [
"First Message",
"Second One",
"Third really really really long message which will type with same speed."
]
var char_timer: Timer
var message_timer: Timer
var current_message_idx = 0
func _ready():
visible_characters = 0
text = messages[current_message_idx]
# Timer to increment number of chars visible
char_timer = Timer.new()
add_child(char_timer)
char_timer.wait_time = 0.1
char_timer.autostart = true
char_timer.connect("timeout", self, "timer_tick")
char_timer.start()
# Timer to go to next message in messages list
message_timer = Timer.new()
add_child(message_timer)
message_timer.wait_time = 2
message_timer.connect("timeout", self, "next_message")
message_timer.one_shot = true
func timer_tick():
visible_characters += 1
if visible_characters >= text.length():
visible_characters = -1
char_timer.stop()
message_timer.start()
func next_message():
current_message_idx += 1
if current_message_idx < messages.size():
visible_characters = 0
text = messages[current_message_idx]
char_timer.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment