Reputation: 85
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
Upvotes: 3
Views: 860
Reputation: 10320
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
Upvotes: 2