Question

I made a bitmap font using Hiero, called default.fnt and default.png. I can use these as a BitmapFont in LibGDX, and draw text with the font without problems, using font.draw(). But I can't use this font as the default font in a Skin. I've used the uiskin.json file from here(along with the rest of the skin, but I deleted the Droid Sans files before making my own font), because I have no idea how to make one of my own. From what I've read on the Internet, the .json file is correctly set up: it has the line com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } }, which should make the default.fnt the default font for widgets that use the skin. Still, when I run the program, I see this:

Label in window that should show text shows only part of an A, buttons that should have labels empty

There should be a label above the buttons, and the buttons should have text.

If I do this: startGameButton.getStyle().font = font;, where startGameButton is one of the buttons, and font is the BitmapFont created like this: font = new BitmapFont(Gdx.files.internal("uiskin/default.fnt"), Gdx.files.internal("uiskin/default.png"), false);, the buttons shows the text properly. I don't want to do this since it feels too much like a hack.

I'm following this tutorial, but I've had to look some things up in later revisions of his code, because LibGDX has changed since it was written.

MenuScreen.java(the screen where there are problems)

AbstractScreen.java

Also please tell me if there's a better way to make the menu UI, or if you need other files. The uiskin.json is linked above.

Thank you.

Was it helpful?

Solution

I fixed it. The Droid Sans bitmap image existed in two places, it was part of uiskin.png too. I don't know how, but it probably read the font's letters from that file instead of default.png. So in the end I just renamed the font's .fnt and .png(and the file parameter in the .fnt) and did a search-replace inside the skin's .json, and it all works fine now. I don't know exactly what caused it, but maybe default-font is a reserved word or something.

Anyway, it works now. Thanks to Jyro117 for making me think maybe I shouldn't replace the default but add my own font.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top