如何使用 libgdx 渲染表情符号

How to render an emoji with libgdx(如何使用 libgdx 渲染表情符号)
本文介绍了如何使用 libgdx 渲染表情符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经加载了一个 支持表情符号的字体,我正在尝试渲染一个带有表情符号的字符串与 libgdx.但是,它会呈现文本,而不是表情符号.

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.

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);

渲染字体

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  uD83DuDC49 test uD83DuDC49 uD83DuDC4D test uD83DuDE03"
renderFont(sb, emojiFont, str, x, y, new Color(-597249));

输出

emoji 测试测试

  1. 为什么 libgdx 不呈现表情符号?
  2. 我需要更改哪些内容才能呈现表情符号?

推荐答案

FreeTypeFontGenerator 从您的 TTF 文件创建一个 BitmapFont.您创建的字体很可能不包含表情符号.

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";

这篇关于如何使用 libgdx 渲染表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)