Anyone have this class or can help me for make?
BitmapFonts Class?
I do, actually! Here’s a link.
It’s probably a little rough, since I wasn’t intending to release it publicly (yet), but it should do the job. It uses FlashPunk’s Tilemap to display the characters, and it supports line breaks and centering.
Here’s some sample code to initialize a 14x16 bitmap font and add it to the world:
[Embed(source = 'smallFont.png')]
static private const SMALLFONT:Class;
static public const smallFont:Tilemap = new Tilemap(SMALLFONT, 14, 16, 14, 16);
var newText:BitmapText;
newText = new BitmapText(smallFont);
newText.width = 300;
newText.height = 16;
newText.centered = true;
newText.text = "Hello world!"
addGraphic(newText);
i not understund the unicode offset, if i set it at 30 the first char is the “1”?
Sure, no problem. Here’s an example. Just a note: the font is uppercase-only, so all of the lowercase characters are exact copies of their uppercase equivalents.
This font would use offset 33, because the first character in the image (the one in the top-left) is “!”, which is ASCII/Unicode character #33. For reference, use this table. 33 is the first visible character in ASCII, so that’s why I chose it as the default offset.
Sometimes, you’ll have a font which you’re only using for numbers on the HUD. It might look something like this:
So, in that case, your offset would be 48, since that’s the ASCII value for the character 0, which is the first character in the font image.
Hope that helps!
Nice font!
The dimensions of the image shouldn’t have an effect on the performance, so what you have should be fine. In case you’re still having troubles, it looks like you’ll want your font to use an offset of 32, since you also included the space character.