我过去编写了一些代码来检查文本以查找将更改文本颜色的颜色代码。例如:
画这个:
你好,我的名字是约翰
绘制时会给出这样的结果: Hello my name is john
but "is john"将为蓝色,因为我使用了 &b 颜色代码。我基本上是在模仿ansi,但针对的是java。
现在我想像 LibGDX 的 BitMapFont.drawWrapped(...)
一样对文本进行换行,但仍然使用颜色代码。有人知道怎么做吗?我最终可能会弄清楚,但我只是想知道是否有比我更好的方法。
最佳答案
支持颜色标记:Color Markup Language :
The BitmapFontCache class supports in-string colored text through a simple markup language.
Markup is disabled by default. Use the method BitmapFont.setMarkupEnabled() 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 xxxxxxxx in the form RRGGBBAA where 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 # nor [, and cannot contain ]. Also, any occurrence of [ in the color name must not be escaped.
For a sample code see the test class BitmapFontTest.
关于java - LibGDX WrappedText 但通过在文本中使用颜色(java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26650403/