从 getCharBoundaries 到 BitMapData
我正在尝试将文本字段中的所有字母转换为位图数据。然后我想为他们每个人制作动画。我可以使用 getCharBoundaries 返回矩形数组。那么如何将每个字母转换为 BitMapData 呢?
package
{
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
public class LetterBitmapData extends Sprite
{
private var tf:TextField;
private var letterSprite:Sprite;
public function LetterBitmapData()
{
makeTF();
getRectangles();
};
private function makeTF():void
{
tf = new TextField();
tf.width = 400;
tf.height = 100;
tf.selectable = false;
tf.multiline = true;
tf.wordWrap = true;
tf.text = "Now is the winter of our discontent made glorious summer by this sun of York.";
tf.setTextFormat(new TextFormat("_sans", 16, 0));
addChild(tf);
}
private function getRectangles():Array
{
var result:Array = [];
var rectangle:Rectangle;
for (var i:int = 0; i < tf.text.length; i++)
{
rectangle = tf.getCharBoundaries(i);
result.push(rectangle); //create an array of CharBoundary rectangles
//trace("RECTANGLE x: " + rectangle.x + " y: " + rectangle.y + " width: " + rectangle.width + " height: " + rectangle.height );
}
return result;
}
}
}
I'm trying to convert all letters in a textfield to bitmap data. I then want to animate each of them. I'm able to return an array of rectangles using getCharBoundaries. But then how do I convert each letter to BitMapData?
package
{
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
public class LetterBitmapData extends Sprite
{
private var tf:TextField;
private var letterSprite:Sprite;
public function LetterBitmapData()
{
makeTF();
getRectangles();
};
private function makeTF():void
{
tf = new TextField();
tf.width = 400;
tf.height = 100;
tf.selectable = false;
tf.multiline = true;
tf.wordWrap = true;
tf.text = "Now is the winter of our discontent made glorious summer by this sun of York.";
tf.setTextFormat(new TextFormat("_sans", 16, 0));
addChild(tf);
}
private function getRectangles():Array
{
var result:Array = [];
var rectangle:Rectangle;
for (var i:int = 0; i < tf.text.length; i++)
{
rectangle = tf.getCharBoundaries(i);
result.push(rectangle); //create an array of CharBoundary rectangles
//trace("RECTANGLE x: " + rectangle.x + " y: " + rectangle.y + " width: " + rectangle.width + " height: " + rectangle.height );
}
return result;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您使用嵌入字体,您就可以对字母进行动画处理,而无需将它们转换为位图...
您可以创建一个 TextFields 数组,与其特定的矩形关联,而不是创建矩形数组,以便保持每个字母的坐标。之后应该可以为每个文本字段设置动画。
You could animate your letters without turning them into Bitmaps as long as you're using embed fonts that is...
Instead of creating an array of rectangles, you could create an array of TextFields , associated to their specific rectangle in order to keep the coordinates of each letter. After that it should be possible to animate each TextField.