I’m trying to achieve a look for my score display where the leading zeroes before the score are greyed out and the score is not. Does anyone have any suggestions on how this could be done.
Thank you!!
Solution
Thank you to the people who responded. You all helped jog my mind into figuring out a solution!
func style_score_hud(score: int = data.score, label: RichTextLabel = textbox, color_blank: Color = Color.DARK_GRAY, color_highlight: Color = Color.AQUA, number_of_leading_zeroes: int = 8) -> void:
var tag_blank: String = &"[color=#" + str(color_blank.to_html()) + &"]" # BBCode blank color tag
var tag_highlight: String = &"[color=#" + str(color_highlight.to_html()) + &"]" # BBCode highlight color tag
var string: String = tag_blank + str(score).pad_zeros(number_of_leading_zeroes)
for i in range(tag_blank.length(), string.length()):
if string[i] != &"0":
string = string.insert(i, tag_highlight)
break
label.text = string
This seems to depend a bit on your setup.I assume you have your score in some sort of Label or text area. If so, you could use two of them, one for the leading zeros, the other one for the actual score digits. This way you can easily apply different formats to both of them. The downside is that you would have to nail the perfect alignment of two text areas on your screen. But that should be possible.
Another idea, would be to overlay parts of your text with a visual shader which colors it differently. But this solution would have a similar downside: You would have to additionally manage the area where the shader applies.
A third idea, which I think would be best for very fancy digits, is have an individual scene with its own shader for each digit. This should be easiest for mono-spaced fonts. It’s probably the hardest to set up, but you could style each digit very fancy by changing the corresponding shader.
I partially overlayed a Label with a ColorRect. By giving the rectangle the same color as the background – for this you can just use the color picker in the color dialog – and by adding semi-transparency to the color code, it looks like the leading zeros are gray, while the other digits are white.