显示西里尔字母的 libgdx
libgdx 显示西里尔字母时出现以下问题.我举个例子:
I have the following problem with libgdx displaying Cyrillic. I give an example:
这行得通:
System.out.println("абцдеф");
但它什么也没显示:
field = new TextField("абцдеф", style);
然后尝试了,没有成功.
And tried without success.
try {
mmm = new String(t.getBytes(), "UTF-8");
} catch (UnsupportedEncodingException e) {
// Will it ever be thrown?
}
field = new TextField(mmm, style);
如果有人有解决方案,我会很高兴,很多人将不胜感激.
I'll be glad if someone has a solution, many, many will be grateful.
推荐答案
我认为可能缺少一些额外的信息.只要 libgdx 使用 Bitmap-fonts 来显示所有类型的文本.(我认为TextField是scene2dui的一部分)默认的 Bitmap-Generation/Default-libgdx-font 可能只包含 ASCII 码字符和一些额外的字符,但没有西里尔字符.
I think there might be some additional information that is missing. Aslong libgdx is using Bitmap-fonts for displaying all kind of text. (TextField is a part of scene2dui I think) The default Bitmap-Generation / Default-libgdx-font might only contain ASCII-code characters and some additional, but no cyrillic.
这就是为什么您必须在 BitmapFont 中手动提供西里尔字符才能显示它们.用于从 .ttf-Asset 生成 BitmapFonts 的相对较新的 libgdx 扩展也可以生成西里尔字符,如果您定义它们:libGDX 中的 TrueType 字体
That's why you would have to provide cyrillic chars manually in your BitmapFont aswell to be able to display them. The relatively new libgdx-extension for generating BitmapFonts out of an .ttf-Asset can also generate the cyrillic characters if you define them: TrueType Fonts in libGDX
然后,您还可以在您的游戏/应用程序中使用它们,只要您还为您的 TextField/scene2dui 样式定义新生成的字体:Libgdx Scene2d - 设置演员 (TextField) 填充?
Then you'll be also able to use them in your game/app aslong you also define the newly generated font for your TextField / scene2dui style: Libgdx Scene2d - Set actor ( TextField ) padding?
这里还有一些 libgdx-repo 中的测试.如果有误解,请查看:https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/extensions/InternationalFontsTest.java一个>我希望这有帮助!干杯
Here are also some tests in the libgdx-repo. Have a look there if there's a matter of missunderstanding: https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/extensions/InternationalFontsTest.java I hope this helps! cheers
相关文章