Game Development Community

Creating a PNG Font

by Alejandro Portilla · in Torque Game Builder · 03/07/2007 (9:06 am) · 2 replies

I am relatively new to TGB, so sorry if this seems like an easily solvable problem.

I want to create a font using an image instead of a Unicode or TrueType font. This way it would make the font much more visually appealing, as having the ability to have drop shadows, gradients, etc. I have not found an easy way to do this in TGB ( after digging through the documentation for a good hour ), so I thought about writing my own Font class that would load my image as CELL and take in a letter, get it's ASCII, etc and draw the correct image, but it doesn't seem like that would be an easy way to do it as well because each letter would have a unique width ( a 'w' being wider than an 'i' ) and without hard-coding that or writing out each value for each letter ( being a pain if values ever change ) I don't think that would be a viable solution. Not to mention that I have not found a simple render function to draw a frame of an image without making an instance of an object and assigning that object an image. If anybody has any solutions/suggestions/help, it would be much appreciated. Thanks ahead of time.

About the author

Recent Threads


#1
03/07/2007 (1:43 pm)
You can easily export the fonts used by TGB as PNGs, modify them as you see fit, and re-import them into the game using exportCachedFont() and importCachedFont(). You may need to actually have used the font/size once in your scene already before using these, I can't remember. You can call the functions without parameters to get the brief paramter/usage instructions.

Using individual sprites as characters as you describe works too. It also gives you the added flexibility to do per-character effects and animations, but of course it's non-trivial to implement especially if you want support for variable width fonts. Arguably it is also more engine overhead since a long string represents multiple static/animated sprites.
#2
03/08/2007 (12:08 pm)
Alejandro, you could take a look at this .plan I wrote up a few weeks back:

TGB: Bitmap Fonts


It uses a Sprite Sheet and a Tile-Layer to generate 'on the fly' text output, using images in an ImageMap -- it takes into account all possible characters, and I believe the code is fairly easy to follow, so you could add/remove characters as necessary.

It also supports Multiple Fonts in a single Image Map -- using a 'setFont()' function to tell it what font to use for display -- so you could have 3-4 fonts in one image file, to keep all your font graphics together.