Material Box

Material Box

WEBデザイン & フリー素材

Godot - RichTextLabelでテキストを1文字ずつ表示する

Godot

length()でテキストの文字数を取得しループ処理を実装。
awaitで指定した時間置きにadd_text()で一文字ずつ追加する処理を実行させる。


GDScriptではfill()を利用する事で配列の全ての値を指定した値に置き換える事が可能です。
既に値があるものやnullを指定値に変更します。

# RichTextLabelを新規作成
add_child(label)
label.global_position = Vector2(0, 0)
label.size = Vector2(200,200)
var label = RichTextLabel.new()

# 表示するテキスト
var label_text = "Make text come up one character at a time."

# 文字数分のループ処理
for i in label_text.length():
	# awaitで指定秒おきに処理を実行
	await get_tree().create_timer(0.1).timeout
	# テキストから一文字を追加する
	add_text(label_text[i])

BBCodeを有効にしており、タグ付きテキストを追加する場合はappend_text()を利用します。

# RichTextLabelを新規作成
var label = RichTextLabel.new()

# 表示するテキスト
var label_text = "Make text come up one character at a time."

# 文字数分のループ処理
for i in label_text.length():
	# awaitで指定秒おきに処理を実行
	await get_tree().create_timer(0.1).timeout
	# テキストから一文字を追加する
	append_text(label_text[i])

Godot

TitleGodot - RichTextLabelでテキストを1文字ずつ表示する

CategoryGodot

Created

Update

AuthorYousuke.U