jME-TTF - Basic Text
Latest Download
Putting text on the screen with jME-TTF is pretty simple:

TrueTypeNode trueNode = ttf.getText("Hello World", 0, ColorRGBA.White);
trueNode.setLocalTranslation(0, 480, 0);

The first argument to getText is the text to display, the second is the kerning or amount of additional character spacing and the third is the color of the text. There are, of course, additional parameters that allow you to further customize your text:

TrueTypeNode trueNode = ttf.getText("Hello\nWorld", 0, ColorRGBA.White,
    Align.Center, VAlign.Center);
trueNode.setLocalTranslation(320, 240, 0);

For text with a horizontal alignment of Left, default, the origin will be on the left of the text, for a horizontal alignment of Center the origin will be in the center and for Right the origin will remain on the left, but the text will be aligned along the right side of the longest line. For text with a vertical alignment of Top, default, the origin will be on top, for a vertical alignment of Center the origin will be in the center and for Bottom the origin will be on the bottom of the text.

For bitmap texts with an outline you may specify an outline color:

TrueTypeNode trueNode = ((TrueTypeBMP)ttf).getText("Hello World", 0, ColorRGBA.White, ColorRGBA.Blue);
trueNode.setLocalTranslation(0, 480, 0);

Additionally you may supply your own material rather than a color, just omit the ColorRGBA option in the getText method and replace it with a Material. Take note that for bitmap fonts you will want to be sure to set one of the textures in your Material to the texture atlas and be sure to do this after you call getText as the texture atlas may be updated when the text is created:

TrueTypeNode trueNode = ttf.getText("Hello World", 0, myMaterial);
myMaterial.setTexture("Texture", ((TrueTypeBMP)ttf).getAtlas());
trueNode.setLocalTranslation(0, 480, 0);

You can change the text or alignment of the TrueTypeNode after it is created, however, any changes will not be reflected until TrueTypeNode.updateGeometry is called:

trueNode.setText("Lorem ipsum...");

For bitmap texts you may also want to reset the texture on the material to the TrueTypeFont's texture atlas as the atlas may have been updated with new characters. See the notes section for more information about using an AtlasListener to listen for changes in the atlas.
Designed by Adam T. Ryder