不同分辨率下的字体Libgdx

3

我有一个字体问题:

我有一个位图字体,并在Label中使用它来书写单词,我的问题是当更改屏幕分辨率时,字体看起来像素化了。

通过查看网络,我发现可以使用FreeTypeFontGenerator类解决这个问题,但我不明白如何操作。

您能给我一些提示吗?

感谢您的时间。


1
如果您正在使用位图字体,并且您的分辨率(实际上是屏幕上文本的大小)超出了位图字体字符大小的分辨率,则预计字体会看起来像素化。您可以使用FreeTypeFontGenerator,但要小心不要生成太小的字体。否则它将再次变得像素化。关键在于不要将某物扩展到其实际尺寸之外。 - Seyf
1个回答

2
要使用FreeTypeFontGenerator类,您必须将Gdx-FreeType Extension添加到您的项目中。如果您正在使用Gradle进行开发,请将以下dependenies添加到您的项目根gradle.build文件中: 核心依赖项:
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"

桌面依赖:
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"

安卓依赖:
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"

iOS 依赖:
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"

HTML 依赖项:不兼容!
然后,将您的字体ttf文件添加到资产目录中,并像这样使用它:
FreeTypeFontGenerator generator = new  FreeTypeFontGenerator(Gdx.files.internal("myfont.ttf"));
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 12;
BitmapFont font12 = generator.generateFont(parameter); // font size 12 pixels
generator.dispose(); // don't forget to dispose to avoid memory leaks!

更多信息:Gdx FreeType on Libgdx Wiki

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接