Godot Version
4.2.2.stable
Question
I have been trying to create a custom RichTextEffect that subtly shakes words around. I am able to get the font-specific glyph index of each character, but I can’t figure out a way to compare that glyph index to any specified character (in this case, " ", “.”, “,”, and “-”.) I’ve tried usingfont_get_char_from_glyph_index
and font_get_glyph_index
, but it doesn’t seem to give the results I’m expecting.
How can I get the individual character within a RichTextEffect and see if it’s equal to another character?
Here’s my script:
@tool
extends RichTextEffect
class_name RichTextNervous
var bbcode = "nervous"
var SPLITTERS = [" ", ".", ',', '-']
var _word = 0.0
func _process_custom_fx(char_fx):
if char_fx.relative_index == 0:
_word = 0
var scale:float = char_fx.env.get("scale", 1.0)
var freq:float = char_fx.env.get("freq", 8.0)
#print(str(int("a"[0])))
#print(str(TextServerManager.get_primary_interface().font_get_glyph_index(char_fx.font, 1, 0, 0)))
#print(str(TextServerManager.get_primary_interface().font_get_char_from_glyph_index(char_fx.font, 1, char_fx.glyph_index)))
if SPLITTERS.has(TextServerManager.get_primary_interface().font_get_char_from_glyph_index(char_fx.font, 1, char_fx.glyph_index)):
_word += 1
var s = fmod((_word + char_fx.elapsed_time) * PI * 1.25, PI * 2.0)
var p = sin(char_fx.elapsed_time * freq)
char_fx.offset.x += sin(s) * p * scale
char_fx.offset.y += cos(s) * p * scale
return true