3

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

  • 1
    If you are using bitmap font and if your resolution (actually, the size of the text on the screen) goes beyond the resolution of your bitmap font character sizes, it is expected for the font to look pixelated. You can use FreeTypeFontGenerator, yes, but be careful not to generate the font too small. Otherwise it will look pixelated again. The key here is not to expand something beyond its actual dimensions. – Seyf Sep 29 '14 at 12:20

1 Answers1

2

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

Daahrien
  • 10,190
  • 6
  • 39
  • 71