本文介绍了如何在libgdx中绘制平滑的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在 libgdx 上的android游戏中绘制简单的文本,但是看起来很清晰.如何使文本在不同的分辨率下看起来平滑?我的代码:
I try to draw simple text in my android game on libgdx, but it's look sharp. How to make text look smooth in different resolutions? My Code:
private BitmapFont font;
font = new BitmapFont();
font.scale((ppuX*0.02f));
font.draw(spb, "Score:", width/2-ppuX*2f, height-0.5f*ppuY);
推荐答案
一种解决方案是使用FreeType扩展程序对libgdx的使用,如此处.这使您可以从.ttf字体动态生成位图字体.通常,一旦知道目标分辨率,便会在启动时执行此操作.
One solution is to use the FreeType extension to libgdx, as described here. This allows you to generate a bitmap font on the fly from a .ttf font. Typically you would do this at startup time once you know the target resolution.
这是一个例子:
int viewportHeight;
BitmapFont titleFont;
BitmapFont textFont;
private void createFonts() {
FileHandle fontFile = Gdx.files.internal("data/Roboto-Bold.ttf");
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 12;
textFont = generator.generateFont(parameter);
parameter.size = 24;
titleFont = generator.generateFont(parameter);
generator.dispose();
}
这篇关于如何在libgdx中绘制平滑的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!