从 getCharBoundaries 到 BitMapData

发布于 2024-09-30 09:09:52 字数 1383 浏览 5 评论 0原文

我正在尝试将文本字段中的所有字母转换为位图数据。然后我想为他们每个人制作动画。我可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2024-10-07 09:09:52

只要您使用嵌入字体,您就可以对字母进行动画处理,而无需将它们转换为位图...

您可以创建一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文