Multi-colored text in libgdx

夙愿已清 提交于 2019-12-05 09:19:50

Libgdx offers color markup, which must first be enabled on the BitmapFont with

font.getData().markupEnabled = true;

Text rendered with that font will look for color markup, where colors are surrounded in brackets. Each used color is pushed onto a stack.

  • Named colors (case sensitive): [RED]red [ORANGE]orange
  • Hex colors with optional alpha: [#FF0000]red [#FF000033]transparent
  • A set of empty brackets pops a color off the stack: [BLUE]Blue text[RED]Red text[]Blue text
  • A double bracket [[ represents an escaped bracket character, however it will not work as expected when followed by a closing bracket.

Named colors are defined in the class com.badlogic.gdx.graphics.Colors, and can be added with Colors.put("NAME", color);.

Hopefully this isn't super late.

I haven't tried it your way, but I bet you would have to overwrite the setText method and then set the colors for the specific points you want. start and end are indices for the pieces of text you want in that particular color.

I have implemented a MulticolorTextArea here: https://github.com/AnEmortalKid/MulticolorTextArea/tree/mta-release

Hopefully this helps out.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!