Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font for different resolution Libgdx

I have a problem with fonts:

I have a bitmapFont and I use it for write words in Label, my problem is that when change the resolution of screen the font seems pixellated.

Looking at network I discovered that this problem can be resolved using FreeTypeFontGenerator class, but I don't understand how.

Could you give me a tip about.

Thank for your time

like image 508
programmer_dna Avatar asked Feb 18 '26 16:02

programmer_dna


1 Answers

To be able to use FreeTypeFontGenerator class, you must add the Gdx-FreeType Extension to your projects. If you're developing using Gradle, add the following dependenies to your project root gradle.build file:

Core Dependency:

compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"

Desktop Dependency:

compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"

Android Dependency:

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 Dependency:

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

HTML Dependency: Not compatible!

Then, add your font ttf file in your assets directory and use it like this:

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!

More information: Gdx FreeType on Libgdx Wiki

like image 122
Lestat Avatar answered Feb 20 '26 04:02

Lestat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!