Today I cleaned up the code for my Bitmap Font Tools to be a bit more legible for public use. These tools allow you to generate bitmap font .swfs and load them into your Flash MX games/animations. For a demo .swf, info, and to download click 'more'.
There are two parts, the Flash Bitmap Font Writer(a Java executable) and the Bitmap Font Engine(a Flash MX movie clip).
The Flash Bitmap Font Writer takes a preformatted bitmap image like the one above and cuts up each individual letter. It then adds an alpha channel, and a 1-pixel transparent border to each image. The border keeps Flash from accidentally drawing the type incorrectly. It then embeds each letter into a swf file as an attachMovie()-able clip. You can then use the Bitmap Font Engine movie clip within flash to load the swf and display type. Type can currently be moved, faded, and scaled in/out using a multitude of different easing algorithms (courtesy of Robert Penner ).
Why use bitmap fonts?
Flash uses vectors for its type. Putting a ton of type on a page can really slow things down. Using bitmap fonts keeps flash from doing heavy anti-aliasing and vector curve processing. Also, bitmap fonts allow you to use many colors in a font, instead of being limited to one.
What do I need?
Java 1.4.1(installed and configured correctly), Flash MX, and some beginner/intermediate programming knowledge. For more information, check out the README file.
What does the ActionScript look like?
This code loads a font swf:
mm1 = bfe.loadFont("mm1_font.swf");
This code fades in a string, waits 50 frames, then fades out:
myText = BitmapFontEngine.addInstance("This is myText!", myFont, xPos, yPos, xWidth, yWidth, 50);
myTransition = new Transition(null,null,null,null,0);
myText.setTransitionIn(myTransition);
myText.setTransitionOut(myTransition);
How big is it?
The font engine is ~6K and a font is 8-15K or so. The entire download with java application is about 3MB.
Can I get the source code and screw with things?
It comes with the Flash and Java source and an Ant build file. Type 'ant deploy' and it will compile into the 'dist' directory.
In order to create the game/animation Penguin Blood Ninja Fiasco I wanted an authentic old school game feel. Flash's vector technology is, in a lot of ways, too high tech. So I decided to old school it up a bit by not using those flashy 90s 'TrueType' fonts and use 'bitmap' style fonts like most games do. In fact a lot of newer games you see still use bitmap fonts. And so, considering how many bitmap fonts are still in use by games, how many are freely available, and how I haven't seen any bitmap font resources for flash, I thought it would be a good idea to create a couple bitmap font tools, not only for myself, but for the gaming and flash community. I thought the time it would take me to write these programs would save me time in the future. It didn't save me any, but maybe it can save some for you! :)