Connected the dialog box to the NPC
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class_name ArrowGirl extends Area2D
|
class_name ArrowGirl extends Area2D
|
||||||
|
|
||||||
|
@onready var _dialogController = $/root/Scene/DialogController
|
||||||
@onready var _sprite = $AnimatedSprite2D
|
@onready var _sprite = $AnimatedSprite2D
|
||||||
|
|
||||||
#boilerplate
|
#boilerplate
|
||||||
@@ -12,3 +13,11 @@ func _on_animation_finished() -> void:
|
|||||||
_sprite.play("idle_glance", 2)
|
_sprite.play("idle_glance", 2)
|
||||||
else:
|
else:
|
||||||
_sprite.play("idle", 2)
|
_sprite.play("idle", 2)
|
||||||
|
|
||||||
|
func _on_body_entered(body) -> void:
|
||||||
|
if body is BoxBoy:
|
||||||
|
_dialogController.set_dialog("Hello.", 0.2)
|
||||||
|
|
||||||
|
func _on_body_exited(body) -> void:
|
||||||
|
if body is BoxBoy:
|
||||||
|
_dialogController.set_dialog("")
|
||||||
|
|||||||
@@ -52,4 +52,6 @@ metadata/_edit_lock_ = true
|
|||||||
shape = SubResource("RectangleShape2D_53v1e")
|
shape = SubResource("RectangleShape2D_53v1e")
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
||||||
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
|
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ extends Node
|
|||||||
@export var dialogContainer: MarginContainer
|
@export var dialogContainer: MarginContainer
|
||||||
@export var dialogTextLabel: RichTextLabel
|
@export var dialogTextLabel: RichTextLabel
|
||||||
|
|
||||||
const INCREMENT: float = 0.01
|
func set_dialog(text: String, seconds: float = 1) -> void:
|
||||||
|
|
||||||
func set_dialog(text: String) -> void:
|
|
||||||
dialogTextLabel.text = text
|
dialogTextLabel.text = text
|
||||||
dialogTextLabel.visible_ratio = 0
|
dialogTextLabel.visible_ratio = 0
|
||||||
var ratio: float = 0
|
var ratio: float = 0
|
||||||
@@ -16,10 +14,12 @@ func set_dialog(text: String) -> void:
|
|||||||
else:
|
else:
|
||||||
dialogContainer.visible = true
|
dialogContainer.visible = true
|
||||||
|
|
||||||
|
var increment: float = (1 / seconds)/ 60.0
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
#don't interfere with other timers
|
#don't interfere with other timers
|
||||||
if dialogTextLabel.visible_ratio < ratio or dialogTextLabel.visible_ratio >= 1:
|
if dialogTextLabel.visible_ratio < ratio or dialogTextLabel.visible_ratio >= 1:
|
||||||
return
|
return
|
||||||
dialogTextLabel.visible_ratio += INCREMENT
|
dialogTextLabel.visible_ratio += increment
|
||||||
ratio = dialogTextLabel.visible_ratio
|
ratio = dialogTextLabel.visible_ratio
|
||||||
await get_tree().create_timer(INCREMENT).timeout
|
await get_tree().create_timer(1.0/60.0).timeout #update proportional to 60 FPS
|
||||||
|
|||||||
Reference in New Issue
Block a user