Flash AS3 draw TextField to BitmapData with rotation
I want to draw text to a bitmapData and allow it to be rotated but rotating the text makes it disappear :(
The code I am using resembles something like this :
var tf : TextField = new TextField(开发者_开发问答);
tf.text = "testing";
var mat : Matrix = new Matrix();
mat.identity();
mat.rotate(angle);
var img : BitmapData = new BitmapData(500, 500, true, 0);
img.draw(tf, mat, null, null, null, true);
If I comment out mat.rotate(angle); the text appears fine. It's not the angle value because I can do this :
var tf : TextField = new TextField();
tf.text = "testing";
var mat : Matrix = new Matrix();
mat.identity();
mat.rotate(angle);
var img : BitmapData = new BitmapData(500, 500, true, 0);
var txtImg : BitmapData = new BitmapData(500, 500, true, 0);
txtImg.draw(tf, null, null, null, null, true);
img. draw(txtImg , mat, null, null, null, true);
and the text will appear rotated (which is a workaround to this problem but I need to create 2 BitmapData images and call draw twice which costs CPU and memory). I would much rather not have to do all this extra processing to get an effect that should, in theory, work with a single call to the draw method. What am I doing wrong?
Thanks
You should try
tf.embedFonts = true;
If you don't use embedded fonts, Flash won't be able to do anything graphicaly advanced with your TextField.
From @yesterday's comment (for a better formatting):
For others that might have the same problem, I used the Embed tag to embed my font. Something along the line of :
[Embed(source='../libs/font.ttf', fontFamily='MyFont', embedAsCFF='false')]
private const MyFont : Class;
and I call
Font.registerFont(MyFont);
somewhere in the code before using the font.
精彩评论