The createTextSingle method instantiates a single Geometry with a single Mesh with all the characters supplied to the String argument. This mesh can be aligned relative to its origin vertically and horizontally using one of TrueTypeFont.VERTICAL_BOTTOM, TrueTypeFont.VERTICAL_CENTER, TrueTypeFont.VERTICAL_TOP, TrueTypeFont.HORIZONTAL_LEFT, TrueTypeFont.HORIZONTAL_CENTER, or TrueTypeFont.HORIZONTAL_RIGHT. The final argument is the amount of kerning, additional space between each character, to use.
It should be noted that the createTextSingle method will return null if there was a problem creating the mesh such as when a problem was encountered reading the glyphs or too many vertices are required. In such a case you'll want to check the return value and instead try to instantiate with one of the createText methods if null is detected.
The createText method takes in the same arguments as the createTextSingle method, but instead returns a Node. The Node returned here has one or more child Nodes each of which is one line of text. If the String supplied to the method contains no line breaks the Node will have only one child Node. Each child Node has one Geometry for each character in the line of text as a child. These Nodes will have no children if there were errors creating the glyph meshes. Be sure to test your fonts!
You can determin the width of one line of text with the getLineWidth(String text, float kerning) method. This method will return the width of the text in world units:
Each glyph mesh is cached when you call one of the createText or createTextSingle methods. Triangulating a glyph is a bit of a process, one or two glyphs is not a big deal, but triangulating lots of text can bog down the system. I recommend you pre-cache whatever characters you expect to use in your scene during load time by calling one of the createText methods.
Designed by Adam T. Ryder
Create your own unique website with customizable templates.