Scale a Bitmapfont in LibGDX
Asked Answered
O

4

20

How can I scale a Bitmapfont object in LibGDX? It seems the method setScale is no longer available.

Ous answered 27/4, 2015 at 22:26 Comment(0)
S
14

It is not recommended to scale Bitmap font, because it looks pixlated when enlarged(which I believe is ugly)

It is recommended to use freetype generator for resizing your fonts

If you still want use bitmapFont Tenfour04 is correct

Spokane answered 28/4, 2015 at 10:12 Comment(4)
Can I use a large enough font so that I can resize it with getData().setScale(...,...) without looking ugly?Ous
Sure, just use a larger font and make sure you load its texture with mip-mapping turned on and use the filters (MipMapLinearLinear, Linear).Sapor
I am using Freetype generator, but it seems like it does not automatically scales down when running on a small resolution screen. How can i scale down Freetype font according to screen resolution?Yan
I'm using freetype generator, but as it creates a whole new texture, I'm getting lots of flushes called because it constantly switches between my one big TextureAtlas with all my images, and the font Texture. Is there anyway to combine these into one TextureAtlas, at run time?Skyla
S
38

Use bitmapFont.getData().setScale(float x, float y).

Sapor answered 28/4, 2015 at 2:15 Comment(1)
where bitmapFont = new BitmapFont();Ellison
S
14

It is not recommended to scale Bitmap font, because it looks pixlated when enlarged(which I believe is ugly)

It is recommended to use freetype generator for resizing your fonts

If you still want use bitmapFont Tenfour04 is correct

Spokane answered 28/4, 2015 at 10:12 Comment(4)
Can I use a large enough font so that I can resize it with getData().setScale(...,...) without looking ugly?Ous
Sure, just use a larger font and make sure you load its texture with mip-mapping turned on and use the filters (MipMapLinearLinear, Linear).Sapor
I am using Freetype generator, but it seems like it does not automatically scales down when running on a small resolution screen. How can i scale down Freetype font according to screen resolution?Yan
I'm using freetype generator, but as it creates a whole new texture, I'm getting lots of flushes called because it constantly switches between my one big TextureAtlas with all my images, and the font Texture. Is there anyway to combine these into one TextureAtlas, at run time?Skyla
C
4

As Fish mentioned, it is recommended to use freetype generator as following:

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/timesBold.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();

Then change the font size in parameter and initialize BitmapFont:

fontParameter.size = 18;
BitmapFont font = fontGenerator.generateFont(fontParameter);

It is also needed to include libgdx-freetype.so in armeabi folder of your project.

Cain answered 22/11, 2016 at 10:29 Comment(2)
could you please clarify how to determine what ttf fonts are actually available & where they are located on the device? Are these gdx fonts or android system fonts? thxHelgahelge
You can find .ttf files in the font folder of your windows OS. Then copy your desired font family file and locate it in the asset folder of your Libgdx project.Cain
H
0

You can assign Font Size to FreeTypeFontParameter while loading font

 FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("Lobster.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 50; // font size
     BitmapFont lobster= generator.generateFont(parameter);
    generator.dispose();
Hatshepsut answered 14/4, 2021 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.