What I did:
Here is a Scene tree (picture attached ↓)
CTC_Sprite should be put at the end of the sentence
This is a [hover speed=30]test[/hover] text. [insert_ctc].[/insert_ctc]
Where insert_ctc tag is CTC should move to
This is code for RichTextEffect insert_ctc
@tool
# Having a class name is handy for picking the effect in the Inspector.
class_name RichTextInsertCtc
extends RichTextEffect
# emit signal with animation name
signal draw_ctc(type :String, position :Vector2)
# To use this effect:
# - Enable BBCode on a RichTextLabel.
# - Register this effect on the label.
# - Use [insert_ctc param=2.0]hello[/insert_ctc] in text.
var bbcode := "insert_ctc"
func _process_custom_fx(char_fx: CharFXTransform) -> bool:
var param: float = char_fx.env.get("param", 1.0)
var position = char_fx.transform.get_origin()
emit_signal("draw_ctc", "white", position)
return true
It calls a signal that passes position of the character
And on RichTextLabel I connect to that signal like so and move sprite to a character position that I get from signal.
extends RichTextLabel
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for i in range(custom_effects.size()):
if custom_effects[i] is RichTextInsertCtc:
custom_effects[i].draw_ctc.connect(_on_show_ctc)
@onready var ctc_sprite: AnimatedSprite2D = $CTC_Sprite
func _on_show_ctc(animation :String, _position :Vector2):
print("show ctc at %s" % _position)
ctc_sprite.position = _position
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass