GarageGames / Torque2D

MIT Licensed Open Source version of Torque 2D game engine from GarageGames
MIT License
1.67k stars 1.56k forks source link

Text sprite #326

Closed greenfire27 closed 8 years ago

greenfire27 commented 8 years ago

This introduces the new TextSprite and FontAsset!

The FontAsset takes FontFile which is the name of a bitmap font file (.fnt). This is the format saved directly by AngleCode's Bitmap Font Generator. The FontAsset parses the file and loads the png images. I've also included in the ToyAssests fonts folder a Config file. Using the config file it should literally take 30 seconds to add a new font!

The TextSprite is the spiritual successor to the ImageFont (which has been removed). The TextSprite uses the FontAsset to correctly position the characters including kerning, if you know what that is. More importantly it has word wrap. You can think of the text sprite as a box that you can position text inside. It has positioning options and overflow options for the horizontal and vertical. Unlike the ImageFont, you can set the size of the TextSprite and even grow it and the the characters will dynamically reposition.

If the TextSprite stopped there it would be extremely useful, but the coolest feature is that you can change the color, scale, and offset of any individual character! This allows for some extremely cool effects like making words jump or creating a dialog box that shows one letter at a time. I demonstrate some of these in the TextSprite Toy that I created to go along with this release.

Enjoy!