The Font Creator plugin is a really nifty tool for any game creator and is easily overlooked unless mentioned. By using it, you can create a bitmap font using any system font you have available. Refer to the Downloading the plugins section in Appendix, Information Fragments, to know how to download a plugin.
We can create bitmap fonts with Font Creator by performing the following steps:
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.
Default.fnt
and make sure it's placed inside the Fonts folder under Interface. This is what the application is looking for during startup.BitmapFont myFont = assetManager.loadFont("Interface/Fonts/MyFont.fnt");
BitmapText text = new BitmapText(myFont, false); hudText.setText("Text!"); hudText.setColor(ColorRGBA.Red); guiNode.attachChild(hudText);
The
BitmapText
class is spatial, and needs to be attached to a node in order to be displayed. The most common node is probably the guiNode
. Spatials added to the guiNode
will be positioned according to the screen space and projected without depth. For this reason, using the guiNode
is suitable for HUD items. Setting the localTranslation
parameter to (0, 0, 0)
will make the text appear in the bottom-left corner of the screen. Instead of using (screenWidth, 0,
screenHeight
), we will place it in the top-right corner.
3.137.163.62