Game Development Reference
In-Depth Information
Note The characters passed to the MOAIFont function are created as a texture and cached, and if
new glyphs are used, they are dynamically created and also cached, thereby providing faster speeds
while rendering text.
Bitmap Fonts
The other way to display text is by using bitmap fonts (from an image file), in which each glyph
(character) is divided by a solid-color guideline, as shown in Figure 10-2 . This way it becomes easy
to create bitmap fonts; however, kerning is not supported by this format.
Figure 10-2. A bitmap font with an outline to indicate the dimensions of the glyph
To use the bitmap, you can use MOAIBitmapFontReader and load the glyphs using the loadPage
function of the newly created bitmapFontReader object.
charcodes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 .,:;!?()&/-"
font = MOAIFont.new()
bitmapFR = MOAIBitmapFontReader.new()
bitmapFR:loadPage( "Font.png", charcodes, 16 )
font:setReader( bitmapFR )
If you use an app like Glyph Designer (from 71 2 ; see www.71squared.com/ ) to create a .fnt file
containing the data related to the bitmap image file, you can use the loadFromBMFont function from
the MOAIFont class, like so:
charcodes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 .,:;!?()&/-"
font = MOAIFont.new()
font:loadFromBMFont( "Font2.png" )
font:preloadGlyphs(charcodes, 64)
 
Search WWH ::




Custom Search