Game Development Reference
In-Depth Information
How to do it…
We can create bitmap fonts with Font Creator by performing the following steps:
1. Right-click on the Fonts folder under Interface in our Project Assets folder.
Select New and then select Other... . Font is located in the GUI folder.
2. Next, we choose the font we would like to use from the available system fonts.
3. In the Configure Font part, we can make adjustments before actually creating the
bitmap. It's recommended to use a power-of-two number for the size.
Tip
A higher resolution will make the text more detailed, but it will at the same time
take up more memory, not only for the bitmap image itself but also for the text
generated. Consider the application requirements or do some testing. You can also
try to adjust the size of the font to fit the bitmap.
4. Once we have our font, there are a couple of ways we can use it. First of all, if we
want to replace the default font used by the application, we have to name the font
Default.fnt and make sure it's placed inside the Fonts folder under Interface .
This is what the application is looking for during startup.
5. Another way to use the custom font is to load it in the application by using the fol-
lowing code:
BitmapFont myFont = assetManager.loadFont("Interface/
Fonts/MyFont.fnt");
6. It can then be used to create text that can be placed anywhere on the screen, as
shown in the following code:
BitmapText text = new BitmapText(myFont, false);
hudText.setText("Text!");
hudText.setColor(ColorRGBA.Red);
guiNode.attachChild(hudText);
Search WWH ::




Custom Search