BitmapFontCache class supports in-string colored text through a simple markup language.
Markup is disabled by default. Use the public member font.getData().markupEnabled to turn it on/off.
The markup syntax is really simple but still versatile:
- [name] Sets the color by name. There are a few predefined colors, see the Colors.reset() method for an exhaustive list. Users can define their own colors through the methods of the Colors class.
- [#xxxxxxxx] Sets the color specified by the hex value
xxxxxxxxin the form
RRGGBBAAwhere AA is optional and defaults to 0xFF.
-  Sets the color to the previous color (kind of optional end tag)
- [[ Escapes the left bracket.
Notice that color names are case-sensitive, cannot be empty, cannot start with neither
[, and cannot contain
]. Also, any occurrence of
[ in the color name must not be escaped.
Unknown colors, illegal hex codes and unclosed tags are silently ignored and treated as normal text.
For a sample code see the test class BitmapFontTest.
Note: When using with Scene2D you have to remove the fontColor property from LabelStyle definition in the skin.json file to have markup coloring work with a Label.