When I try to draw a string in libGDX using a BitmapFont I only get filled boxes instead of characters, with the specified font color.
I haven’t found any information googling so I’m asking here.
Never seen that.
If you open the png in like photoshop, are the characters all fine and visible ?
Maybe you do something really wrong with the code, would help if you post a minimal scenario
I open the font in the image viewer and the background is transparent.
Here’s the loading/declaration
BitmapFont font = new BitmapFont(Gdx.files.internal("data/font.fnt"), false);
And the rendering code
batch.begin();
font.draw(batch, "blabla", 10, 10);
stage.draw();
batch.end();
Never used Stage before, but I dont think it would be a problems
It does sound like the alpha channel has a problem or the texture is destroyed or the png has like a color format not supported by the libgdx png reader
Try posting it here : http://www.badlogicgames.com/forum/viewforum.php?f=11
Mario, one of the creators checks there really frequently and not as often here.
Try this instead:
batch.begin();
font.draw(batch, "blabla", 10, 10);
batch.end();
//Stage.draw will call begin and end on the given batch
stage.draw();
If you want to include text in the same batch as the rest of your stage sprites, use the Label UI.
Thanks, davedes.
Another question I have:
Is it possible to change the text/font color without changing the file itself?
Well font.setColor(Color)
Since the png has white characters, you can filter it to any color, which is done internally, by using that call
That doesn’t seem to work. The characters in the font.png are all white, but they always display as black ingame.
don’t you need batch.setColor?
Tried changing the batch color to something else, no change.
Tried changing batch color to white and font color to something else and no change.
no its font.setColor if you just want to change font color
there is something from with you font I guess.
What tool are you using to create them ?
You might wanna post your whole code and font files…
I’ve tried fonts created with “Hiero” and “BMFont”, both look/behave the same.
Both should work.
This tool is better IMO:
http://twl.l33tlabs.org/themer/fonttool.jnlp
If your white fonts are not being recolored, I’m guessing you have something else in your code interfering (i.e. calls to glTexEnvi or a custom shader).
Try this test case:
http://www.java-gaming.org/?action=pastebin&id=282
Other than that, learn to debug…
Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features.
This is really off-topic but jhallenberg you were using Slick2D a week or two ago, what made you switch over to LibGDX? The reason I’m asking is because I’m working on a Slick2D game but I’ve learned that LibGDX is a superior engine. I’m not sure if I should finish my game in Slick2D or switch over to LibGDX first, what did you experience with the two engines? Thanks in advance in you have time to reply.
I switched due to libGDX having built in box2d mainly, I didn’t get very far into using slick2d either so it wasn’t a big deal.
Ah good to know, thanks.
Why do you hate TWL?
Why would your hatred of TWL have anything to do with this incredibly useful tool that Matthias has made open source?
I am not a Windows user so BMFont is useless to me.
I got the font coloring to work. It was a really dumb error made by me that I didn’t see until now. I placed the new font files in the wrong folder so I kept using the same ones… :emo: