Godot Version
<–4–>
I’ve been trying to add icons that change as the dialogue progresses but i keep running in to issues can, can anyone lead me to the right direction on how to add icons?
<–4–>
I’ve been trying to add icons that change as the dialogue progresses but i keep running in to issues can, can anyone lead me to the right direction on how to add icons?
You need to show code and explain what is going wrong.
Or, use an existing dialogue system that features icons.
Search for Godot 4 Dialogue System
dialogue box code
extends Node2D
@onready var richlabel = $tehtestxt/painel/teskbotainer/Tesktbokt/speaking
@onready var LDT = $tehtestxt/LDT
var text = “”
var letter_index = 0
var letter_time = 0.03
var space_time = 0.06
var punctuation_time = 0.2
signal finished_displaying()
func displaying(text_to_display: String):
text = text_to_display
richlabel.text = text_to_display
richlabel.text = ""
_display_letter()
func _display_letter():
richlabel.text += text[letter_index]
letter_index += 1
if letter_index >= text.length():
finished_displaying.emit()
return
match text[letter_index]:
"!",".",",","?":
LDT.start(punctuation_time)
" ":
LDT.start(space_time)
_:
LDT.start(letter_time)
func _unhandled_input(event):
if event.is_action_pressed(“unchoosen”):
letter_time = 0.0000001
space_time = 0.0000001
punctuation_time = 0.00000001
func _on_ldt_timeout():
_display_letter()
Global script code
extends Node
#dialogue box scene
@onready var TBS = preload(“res://Scenes/UI Elements/dialogue_manager.tscn”)
#dialogue lines
var DL: Array[String] =
#current line index
var CLI = 0
#textbox
var TB
#textboxposition
var TBp: Vector2
var dialogue_active = false
var can_advance = false
func start_dialogue(position: Vector2,lines:Array[String]):
if dialogue_active:
return
DL = lines
TBp = position
#showtextbox
_STB()
dialogue_active = true
func _STB():
TB = TBS.instantiate()
TB.finished_displaying.connect(_on_text_box_finished_display)
get_tree().root.add_child(TB)
TB.global_position = TBp
TB.displaying(DL[CLI])
can_advance = false
func _on_text_box_finished_display():
can_advance = true
func _unhandled_input(event):
if (
event.is_action_pressed(“Choosen”) &&
dialogue_active &&
can_advance
):
TB.queue_free()
CLI += 1
if CLI >= DL.size():
dialogue_active = false
CLI = 0
return
_STB()
this is the code from the video, how can i make an icon change it’s texture with the text?