diff options
author | rom <romangraef@gmail.com> | 2021-04-25 00:35:12 +0200 |
---|---|---|
committer | rom <romangraef@gmail.com> | 2021-04-25 00:35:12 +0200 |
commit | 7d3d98f6b6546d8ddcd7a2a4c8e9431c59880223 (patch) | |
tree | 919961fc23ba8e52a7064d6a7fe3e48a1d68efcc /components | |
parent | 90f80eae757c6232b92561b63fee76ce202f374f (diff) | |
download | ldjam48-7d3d98f6b6546d8ddcd7a2a4c8e9431c59880223.tar.gz ldjam48-7d3d98f6b6546d8ddcd7a2a4c8e9431c59880223.tar.bz2 ldjam48-7d3d98f6b6546d8ddcd7a2a4c8e9431c59880223.zip |
textreveal very gud
Diffstat (limited to 'components')
-rw-r--r-- | components/textreveal.gd | 42 | ||||
-rw-r--r-- | components/textreveal.tscn | 3 |
2 files changed, 28 insertions, 17 deletions
diff --git a/components/textreveal.gd b/components/textreveal.gd index 0d9004c..1685a8d 100644 --- a/components/textreveal.gd +++ b/components/textreveal.gd @@ -1,44 +1,52 @@ extends Node2D -onready var font_source : RichTextLabel = $FontSource signal finished_reveal() -export var text = "Text" +export(String, MULTILINE) var text = "Text" export var speed = 100.0 +############ +# INTERNAL # +############ + + +onready var font_source : RichTextLabel = $FontSource var revealed = 0 var started = false var finished = false - -var label +var t = 0 +onready var label = Label.new() # Called when the node enters the scene tree for the first time. func _ready(): - label = RichTextLabel.new() label.theme = font_source.theme + label.align = Label.ALIGN_CENTER add_child(label) - label.rect_position = -label.rect_size / 2 func _show_text(text): - label.add_text(text) + label.text = text label.rect_position = -label.rect_size / 2 # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - if started: - var reveal = speed * delta - var oldreveal = revealed - revealed += reveal - var t = text.substr(oldreveal, revealed) - _show_text(t) - if text.length() <= revealed: - started = false - finished = true - emit_signal("finished_reveal") + if not started: + return + t += delta * speed + var additional = int(t) + t -= additional + revealed += additional + _show_text(text.substr(0, revealed)) + if text.length() == revealed: + started = false + finished = true + emit_signal("finished_reveal") func start(): started = true + label.text = "" + revealed = 0 + t = 0 finished = false diff --git a/components/textreveal.tscn b/components/textreveal.tscn index 19a1833..a6d9cbb 100644 --- a/components/textreveal.tscn +++ b/components/textreveal.tscn @@ -13,7 +13,10 @@ default_font = SubResource( 1 ) script = ExtResource( 1 ) [node name="FontSource" type="RichTextLabel" parent="."] +grow_horizontal = 2 +grow_vertical = 2 theme = SubResource( 2 ) +text = "AAAAAAAAAAAAAAAAAAAAAAA" __meta__ = { "_edit_use_anchors_": false } |