libgdx with displaying Cyrillic

家住魔仙堡 提交于 2019-12-22 05:09:09

问题


I have the following problem with libgdx displaying Cyrillic. I give an example:

this works:

System.out.println("абцдеф");

but it shows nothing:

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.


回答1:


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.

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

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?

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



来源:https://stackoverflow.com/questions/24933903/libgdx-with-displaying-cyrillic

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