问题
I have loaded a font with emoji support and I am trying to render a string with emoji's with libgdx. However, it renders the text, but not the emojis.
Code
Load Font
FileHandle fontFile = Gdx.files.internal("path/to/file.ttf");
FreeTypeFontGenerator g = new FreeTypeFontGenerator(fontFile);
FreeTypeFontGenerator.FreeTypeFontParameter p = new FreeTypeFontGenerator.FreeTypeFontParameter();
// Some config here with p
BitmapFont emojiFont= g.generateFont(p);
Render Font
public static void renderFont(SpriteBatch sb, BitmapFont font, String msg, float x, float y, Color c) {
font.setColor(c);
font.draw(sb, msg, x, y);
}
String str = "emoji ❤ \uD83D\uDC49 test \uD83D\uDC49 \uD83D\uDC4D test \uD83D\uDE03"
renderFont(sb, emojiFont, str, x, y, new Color(-597249));
Output
emoji test test
Questions
- Why is libgdx not rendering the emojis?
- What do I need to change to render the emojis?
回答1:
FreeTypeFontGenerator creates a BitmapFont from your TTF file. Most likely your created font does not contain the emojis.
You don't show the interesting part of your code: the parameters you set. Add the emojis you want to use to the parameters:
p.characters = "characters you want to use";
来源:https://stackoverflow.com/questions/58635857/how-to-render-an-emoji-with-libgdx