Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set Libgdx bitmap font size?

Tags:

I'm rendering on screen the game fps using bitmap font but there are no methods for the size. This is a problem for me because my camera viewport size is very small so the text when rendered is huge and pixelated.

font.draw(batch, Float.toString(Gdx.graphics.getFramesPerSecond), x, y); 
like image 933
Kevin Bryan Avatar asked Nov 10 '15 15:11

Kevin Bryan


2 Answers

Did you try setScale() method that what i use to resize my font

myFont.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); myFont.setScale(scale); 

if you have trouble, leave a comment

Good Luck !!

Edit :

With the latest libgdx version, try to scale font like this :

myFont.getData().setScale(); 
like image 91
Netero Avatar answered Sep 18 '22 14:09

Netero


I often use what minos23 suggested. But the downfall is that it can look pixelated especially when scaling upwards. A fancy large bitmap font can take up a lot of space and if you need many different fonts you might go over your budget.

By using Gdx.Freetype you are able to create bitmapfonts at runtime from small .ttf files. This means you only need to ship the .ttf files with your app and can generate a font based on user settings like resolution.

Other then scaling and the freetype solution is having multiple bitmaps of different font sizes. This way your fonts stay crisp all time but at the cost of runtime performance to generate the proper fonts.

like image 37
Madmenyo Avatar answered Sep 21 '22 14:09

Madmenyo