Godot Version
4.4.1
So first I’ll ask if this approach to my problem is even possible, and then I’ll explain what I’m actually trying to do.
So firstly, is there any way to access the RichTextLabel that a RichTextEffect is attached to? I would like to retrieve the label’s width and height from within my custom effect.
So my specific use case:
I am trying to create custom BBCode that emulates the old HTML <marquee> tag as closely as possible. In some instances (depending on the parameter), the text should wrap around the screen (ie. when it reaches one side it starts again on the other), in others it reverses direction when it reaches the edge, etc.
The only way I can think to achieve this is to detect the width of the RichTextLabel. I’m not sure if this is even possible.
If there is a better way to do this, I’d love to know, though I am also interested in the answer to the first question as well.
UPDATE
I have found formulas that emulate the behavior I want, but they both rely on defining a width, which currently needs to be done by the user. This is not ideal, as it is not how the original HTML tag worked, so I’m back to the original question. How do I find the width of the RichTextLabel?
Example Code:
In these examples, amplitude is the width that is being set manually.
Scroll Function
func sawtooth_wave(time: float, period: float, amplitude: float) -> float:
var speed = 20/period
var phase := fmod(time / speed, 1.0)
return -amplitude + ((amplitude*2.0) * phase)
Alternate
func bounce_wave(time: float, period: float, amplitude: float = 1.0) -> float:
var t_mod := fmod(time, period)
var phase := t_mod / period # Normalize to 0.0–1.0
if phase < 0.25:
return 4.0 * amplitude * phase
elif phase < 0.75:
return -4.0 * amplitude * (phase - 0.5)
else:
return 4.0 * amplitude * (phase - 1.0)