java - LibGDX WrappedText 但通过在文本中使用颜色(java)

标签 java android colors libgdx ansi-escape

我过去编写了一些代码来检查文本以查找将更改文本颜色的颜色代码。例如:

画这个: 你好,我的名字是约翰 绘制时会给出这样的结果: 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/

相关文章:

java - 将 CodeStar Spring MVC 项目改为 Spring Boot

java - 如何在 Spring WebClient 中验证请求 url?

java - 如何以千字节(kb)或字节为单位获取对象的大小

r - 在 R 中设置自定义色标

c# - 将 int 值转换为渐变中的颜色

java - GroupLayout 未按预期运行

android - Android应用内购,沙盒账号测试

java - 在 Android EditText 中,有没有办法强制每个字符为小写?

java - 如何将Android字符串数组加载到ListView中?

tomcat - IntelliJ Tomcat 控制台颜色输出