Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change font color in Libgdx

Tags:

I'm trying to change the color of the font I use in my application. But whatever I try the font remains black. I made this font using Hiero font tool.

My code is something like this:

SpriteBatch batch = new SpriteBatch();
BitmapFont font = new BtimapFont( Gdx.files.internal(MainAssets.pathToAssets + "font/comic.fnt"), Gdx.files.internal(MainAssets.pathToAssets +  "font/comic.png"), false );

In render where I draw the font:

batch.begin();
font.setColor(1, 0, 0, 1);
font.draw(batch, "Hello World!", 0, 0);
batch.end();

I found a similar issue to mine but there was still no solution.

http://code.google.com/p/libgdx/issues/detail?id=370

like image 941
ruff1991 Avatar asked Oct 06 '12 18:10

ruff1991


Video Answer


3 Answers

You need to set output format with 32-bit depth and white colour with alpha (in case you are using BMFont tool, dont know about the Hiero ).

like image 130
far Avatar answered Oct 09 '22 10:10

far


If your font is black then it won't be colour tinted (which is what you're doing when calling setColor). Try generating the font in Hiero again in white.

like image 28
nmw Avatar answered Oct 09 '22 11:10

nmw


you can use this

font.setColor(Color.BLUE);

simplest way

like image 42
sandeep kundliya Avatar answered Oct 09 '22 09:10

sandeep kundliya