If you want to use a basic font (without effects) in different sizes, it is annoying to have to create a different bitmap font with Hiero every time.
Then you can use the libgdx-extension gdx-freetype.
Then you can use the libgdx-extension gdx-freetype.
To link this extension to your project, you have to go to the libgdx/extensions folder and copy the following files:
armeabi/libgdx-freetype.so -> testgame-android/libs/ameabi/
armeabi-v7a/libgdx-freetype.so -> testgame-android/libs/ameabi-v7a/
gdx-freetype.jar -> testgame/libs/ -> testgame-android/libgdx
gdx-freetype-natives.jar -> testgame-desktop/libs/
In Properties -> Java Build Path -> Libraries -> Add JARs… you add both jar-files to the desktop project and the gdx-freetype.jar to the android project.
After that you simply put the ttf-files of the fonts you want to create “on-the-fly” into a subfolder of assets. (I’m using a free font, that I found at dafont.com)
WIth a FreeTypeFontGenerator you can now generate the BitmapFonts:
FreeTypeFontGenerator generator=new FreeTypeFontGenerator(Gdx.files.internal("font/RawengulkSans.ttf"));
font40=generator.generateFont(40);
font20=generator.generateFont(20);
font10=generator.generateFont(10);
generator.dispose();
// [...]
font40.dispose();
font20.dispose();
font10.dispose();
Important is to dispose the generator as soon as you generated all the BitmapFonts. In dispose() you dispose the generated fonts as always.
No comments:
Post a Comment