Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx doesn't render fonts properly after resume

I'm having problems with fonts using libgdx on android. They work fine when i first open the application. But when I pause the app then resume it, the fonts are rendered incorrectly.

Here's how I create the font.

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/MainFont.ttf"));
LabelStyle ls = new LabelStyle();
ls.font = generator.generateFont(30);
ls.fontColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);       
mPlay = new Label("Play", ls);      
mInstructions = new Label("How To Play", ls);
generator.dispose();

I don't have anything in my Pause/Resume methods, not sure if there should be something there.

Here's what it looks before/after like.

Before

enter image description here

like image 216
user2128112 Avatar asked Dec 27 '13 07:12

user2128112


2 Answers

This looks like a known issue of the LibGDX framework. If it's your case, this bug is solved in newer versions of the framework.

More info on the official issues tracker: https://github.com/libgdx/libgdx/issues/870

Hope it helps.

like image 166
sabadow Avatar answered Oct 20 '22 16:10

sabadow


generator.dispose();

remove this line and put it in dispose method your font is getting dispossed.

like image 25
sandeep kundliya Avatar answered Oct 20 '22 16:10

sandeep kundliya