Flash 8 - bitmapFont class

Tuesday, October 4th, 2005

Here is class for bitmapFont I’ve created for my project.
There is just numbers inside, but you can extend font to your need.
Please let me know if class is useful for you.


[as]import flash.display.*;
import flash.geom.*;
import com.franto.flash8.*;

class bitmapFont {

function bitmapFont() {}

public static function drawText(bmp:BitmapData, color:Number, text:String, position:Point,zoom:Number) {

var x = position.x;
var y = position.y;

var __font:Object = new Object();
__font.char_0 = [7,5,5,5,7];
__font.char_1 = [1,1,1,1,1];
__font.char_2 = [7,1,7,4,7];
__font.char_3 = [7,1,7,1,7];
__font.char_4 = [5,5,7,1,1];
__font.char_5 = [7,4,7,1,7];
__font.char_6 = [4,4,7,5,7];
__font.char_7 = [7,1,1,1,1];
__font.char_8 = [7,5,7,5,7];
__font.char_9 = [7,5,7,1,7];

var bits = 3;

var len = text.length;
for (var i=0;i var char = text.substr(i,1);
var char_data = __font["char_"+char];
var char_len = char_data.length;

for (var j=0;j var data = char_data[j];
for (var b=0;b if (data & Math.pow(2,b)) {
bmp.fillRect(new Rectangle(x+(bits-b)*zoom,y+j*zoom,zoom,zoom), color);
}
}
}
x += zoom * 4;
}
}
}[/as]


And here is example how to write 0123456789 with zoom=3:

[as]bitmapFont.drawText(bmp, 0xffff0000, “0123456789″, new Point(10,10), 3);[/as]

Download class

Enjoy.

AddThis Feed Button

This is some text prior to the author information. You can change this text from the admin section of WP-Gravatar  I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets. Read more from this author


tagged under:

ABOUT THIS AUTHOR

I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets.

Get a Trackback link

No Comments Yet

You can be the first to comment!

Live Preview

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This site is using OpenAvatar based on
Images is enhanced with WordPress Lightbox JS by Zeo
Clicky Web Analytics