- jMonkeyEngine 3.0 Cookbook
- Rickard Edén
- 396字
- 2021-09-03 10:00:47
Creating bitmap fonts with Font Creator
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 how to download a plugin.
How to do it…
We can create bitmap fonts with Font Creator by performing the following steps:
- 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.
- Next, we choose the font we would like to use from the available system fonts.
- 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.
- 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. - Another way to use the custom font is to load it in the application by using the following code:
BitmapFont myFont = assetManager.loadFont("Interface/Fonts/MyFont.fnt");
- 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);
How it works...
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.
- PHP 從入門到項目實踐(超值版)
- Java入門很輕松(微課超值版)
- Production Ready OpenStack:Recipes for Successful Environments
- Scratch 3游戲與人工智能編程完全自學教程
- Full-Stack Vue.js 2 and Laravel 5
- Oracle BAM 11gR1 Handbook
- iOS開發實戰:從入門到上架App Store(第2版) (移動開發叢書)
- 區塊鏈技術進階與實戰(第2版)
- Illustrator CC平面設計實戰從入門到精通(視頻自學全彩版)
- Python Machine Learning Blueprints:Intuitive data projects you can relate to
- SignalR:Real-time Application Development(Second Edition)
- AngularJS UI Development
- Java程序設計入門(第2版)
- Pandas 1.x Cookbook
- H5匠人手冊:霸屏H5實戰解密