在libGDX TrueType字体 [英] TrueType Fonts in libGDX

查看:219
本文介绍了在libGDX TrueType字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我可以在libGDX使用TTF字体?我环顾四周,并看到有关​​StbTrueTypeFont事情,但它似乎并没有在最新的版本。

Does anyone know how I can use a TTF font in libGDX? I have looked around and have seen things about StbTrueTypeFont but it doesn't seem to be in the latest release.

编辑:我发现StbTrueType字体的东西,jar文件位于扩展目录。我已经把它添加到我的项目。现在我只需要弄清楚如何使用它。任何的例子吗?

I found the StbTrueType font stuff, the jar file is located in the extensions directory. I've added it to my project. Now I just need to figure out how to use it. Any examples?

推荐答案

是的,你一定会需要到 GDX-STB-的TrueType JAR添加到您的项目,你说在您的编辑。这里是你将如何使用它,pretty的straighforward ...

Yes you will definitely need to add the gdx-stb-truetype jars to your project as you stated in your edit. Here is how you will use it, pretty straighforward...

首先需要声明的 BitmapFont 和将要使用的字符...

First you need to declare your BitmapFont and the characters you will use...

BitmapFont font;
public static final String FONT_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789][_!$%#@|\\/?-+=()*&.;,{}\"´`'<>";

然后你需要创建字体...

Then you need to create the font...

font = TrueTypeFontFactory.createBitmapFont(Gdx.files.internal("font.ttf"), FONT_CHARACTERS, 12.5f, 7.5f, 1.0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
font.setColor(1f, 0f, 0f, 1f);

您可以使用您传递给 createBitmapFont(),你会看到他们做什么。

You can play with the arguments you pass to createBitmapFont() and you will see what they do.

然后来呈现你会做它,你通常做的字体......

Then to render the font you would do it as you normally do...

batch.begin();
font.draw(font, "This is some text", 10, 10);
batch.end();

这篇关于在libGDX TrueType字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆