jhallenberg
Senior Newbie 
|
 |
«
Posted
2012-10-13 23:12:08 » |
|
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.
|
|
|
|
Cero
|
 |
«
Reply #1 - Posted
2012-10-13 23:50:12 » |
|
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
|
|
|
|
jhallenberg
Senior Newbie 
|
 |
«
Reply #2 - Posted
2012-10-13 23:58:22 » |
|
I open the font in the image viewer and the background is transparent. Here's the loading/declaration 1
| BitmapFont font = new BitmapFont(Gdx.files.internal("data/font.fnt"), false); |
And the rendering code 1 2 3 4 5 6
| batch.begin(); font.draw(batch, "blabla", 10, 10); stage.draw(); batch.end(); |
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Cero
|
 |
«
Reply #3 - Posted
2012-10-14 00:40:33 » |
|
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=11Mario, one of the creators checks there really frequently and not as often here.
|
|
|
|
davedes
|
 |
«
Reply #4 - Posted
2012-10-14 01:47:01 » |
|
Try this instead: 1 2 3 4 5 6
| batch.begin(); font.draw(batch, "blabla", 10, 10); batch.end();
stage.draw(); |
If you want to include text in the same batch as the rest of your stage sprites, use the Label UI.
|
|
|
|
jhallenberg
Senior Newbie 
|
 |
«
Reply #5 - Posted
2012-10-14 02:55:56 » |
|
Thanks, davedes. Another question I have: Is it possible to change the text/font color without changing the file itself?
|
|
|
|
Cero
|
 |
«
Reply #6 - Posted
2012-10-14 03:27:00 » |
|
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
|
|
|
|
jhallenberg
Senior Newbie 
|
 |
«
Reply #7 - Posted
2012-10-14 13:25:13 » |
|
That doesn't seem to work. The characters in the font.png are all white, but they always display as black ingame.
|
|
|
|
JESTERRRRRR
|
 |
«
Reply #8 - Posted
2012-10-14 13:41:56 » |
|
don't you need batch.setColor?
|
|
|
|
jhallenberg
Senior Newbie 
|
 |
«
Reply #9 - Posted
2012-10-14 13:48:58 » |
|
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.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Cero
|
 |
«
Reply #10 - Posted
2012-10-14 14:51:01 » |
|
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...
|
|
|
|
jhallenberg
Senior Newbie 
|
 |
«
Reply #11 - Posted
2012-10-14 19:38:36 » |
|
I've tried fonts created with "Hiero" and "BMFont", both look/behave the same.
|
|
|
|
Cero
|
 |
«
Reply #12 - Posted
2012-10-14 20:11:11 » |
|
I've tried fonts created with "Hiero" and "BMFont", both look/behave the same.
Both should work.
|
|
|
|
|
Cero
|
 |
«
Reply #14 - Posted
2012-10-14 21:29:01 » |
|
Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features.
|
|
|
|
Vladiedoo
|
 |
«
Reply #15 - Posted
2012-10-14 21:39:14 » |
|
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.
|
|
|
|
jhallenberg
Senior Newbie 
|
 |
«
Reply #16 - Posted
2012-10-14 21:52:41 » |
|
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.
|
|
|
|
Vladiedoo
|
 |
«
Reply #17 - Posted
2012-10-14 21:57:15 » |
|
Ah good to know, thanks.
|
|
|
|
davedes
|
 |
«
Reply #18 - Posted
2012-10-14 22:07:56 » |
|
Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features. 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.
|
|
|
|
|
Cero
|
 |
«
Reply #20 - Posted
2012-10-14 23:44:13 » |
|
Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features. Why do you hate TWL? Well I'm open minded to products using TWL - of course it can be good. But I thought the code was a horrible mess and hard to use compared with other alternatives. Why would your hatred of TWL have anything to do with this incredibly useful tool that Matthias has made open source?
Well the gui is incredible confusing. Even the file dialog which looks nothing like a native one, everyone is used to. It doesnt have many features and for that it seems very complicated. Also, I have to choose a ttf... Not a big deal, but I do have all the font installed, so being able to just browse my fonts in hiero is much nicer. And doesnt seem to support .otf files and such @Slick to Libgdx switch We recently refractored and recoded our whole big ass game from Slick to Libgdx. Mainly for the particle system but of course there is lot of other goodies aswell: fast deployment on android if necessary, SpriteBatches, Cameras, natives are within jars, box2d and more
|
|
|
|
Nate
|
 |
«
Reply #21 - Posted
2012-10-15 02:12:25 » |
|
Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features. There are some notes about the different tools here: https://code.google.com/p/libgdx/wiki/HieroIMO the BMFont tool is the best (even though I wrote Hiero :p). Why do you hate TWL?
Well I'm open minded to products using TWL - of course it can be good. But I thought the code was a horrible mess and hard to use compared with other alternatives. That seems odd, TWL has an extremely clean codebase. It is quite complicated but it is a complicated problem, especially when trying to solve it in such a completely configurable/themeable manner. Other toolkits like scene2d have less code but are less powerful. As far as ease of use, I'd agree there that TWL is hard to just pick up and get running.
|
|
|
|
Cero
|
 |
«
Reply #22 - Posted
2012-10-15 02:45:06 » |
|
Why do you hate TWL?
Well I'm open minded to products using TWL - of course it can be good. But I thought the code was a horrible mess and hard to use compared with other alternatives. That seems odd, TWL has an extremely clean codebase. It is quite complicated but it is a complicated problem, especially when trying to solve it in such a completely configurable/themeable manner. Other toolkits like scene2d have less code but are less powerful. As far as ease of use, I'd agree there that TWL is hard to just pick up and get running. I know, I know, but like you said its hard to get in Nifty looked easier still not appealing. I just wrote my own... If you dont need as much functionality, these libs are just overkill - and most games dont have many complex gui elements... scene2d is quite new IIRC or at least you guys have remade it recently or something, so I haven't looked into it yet. When I tried TWL I couldnt even get a button - well after hours of work. I am very fond of "keeping things simple" - lets have all those complex interesting features optional, but a really simple easy to grasp codebase. A simple button should be like 4 lines of code, similar to how AWT would do it: - new button (size, label-String, color) - call render method - check for click event - react to click event Thats it.
|
|
|
|
Nate
|
 |
«
Reply #23 - Posted
2012-10-15 06:11:36 » |
|
scene2d is a few years old. It saw a lot of work a few months ago but was more evolutionary, not a rewrite. I consider scene2d to be very stable. It has a pretty large user base and I've personally developed multiple complex app UIs with it ( eg). It is as simple as you describe when using TWL, with the addition of having to first create a theme that defines how the button looks/acts, and that is where it is easy to get bogged down.
|
|
|
|
Euregan
Junior Newbie
|
 |
«
Reply #24 - Posted
2012-12-12 15:54:54 » |
|
Hello, I have the same problem as jhallenberg. Whenever I draw some text, it appears as black, even though its color is white or anything I want with setColor() (I checked after changing with getColor()). I made the font with BMFont. Other than that the font works fine.
|
|
|
|
Ultroman
|
 |
«
Reply #25 - Posted
2012-12-12 16:06:20 » |
|
Well, I had some similar problems in the beginning. Changing the export option preset to "Outlined text with alpha" fixed it for me. These are my settings. Width/Height: 256 Bitdepth: 8bit Chnl A: outline Font Descriptor: Text Textures: PNG Compression: Deflate
|
- Jonas
|
|
|
Euregan
Junior Newbie
|
 |
«
Reply #26 - Posted
2012-12-12 16:46:36 » |
|
Actually, switching to GL10 has solved the problem, should have thought of that earlier really ...
|
|
|
|
Ultroman
|
 |
«
Reply #27 - Posted
2012-12-12 16:54:21 » |
|
Not a lasting solution, though, is it?
|
- Jonas
|
|
|
Euregan
Junior Newbie
|
 |
«
Reply #28 - Posted
2012-12-12 17:26:41 » |
|
I wish it wouldnt be, sadly the camera system only works with GL10, so I have no choice but to use it anyway
|
|
|
|
cavemaneca
Junior Newbie Medals: 1
|
 |
«
Reply #29 - Posted
2013-02-25 03:02:52 » |
|
I know this is a bit of an old bump (so, sorry for the necro), but this is one of the first google results when trying to figure out this problem, and I have an answer.
Export the fnt file as 32bit if you're using gl2.0. I'm guessing the newer GL version uses the built in channels when changing the color, or something. With 8bit, only the alpha channel can be changed, but with 32bit it can change the color.
|
|
|
|
|