0

我正在尝试制作文本效果,在每一帧上,文本字段的大小都会增加并且不透明度会降低。我正在使用我的动态文本字段的 scaleX 和 scaleY 属性来放大,但这样做是为了保持左侧注册点固定。我想让它径向向外放大,或者中心点固定。谁能告诉我该怎么做?

4

4 回答 4

1
 textfield.x -= textfield.width /2;
 textfield.y -= textfield.height /2;

如果 x 和 y 为 0,这将有所帮助

于 2010-02-16T21:27:11.040 回答
1

TextField您可以轻松地为(即包含 的 Sprite )创建一个包装器,TextField以将注册点强制到中间。如果 TextField 是动态的,请确保将其autoSize设置为LEFT. 此后,您只需将其x/y位置设置为-textField.width*.5/-textField.height*.5。当然,缩放应该应用于父级。

于 2010-02-16T21:29:56.143 回答
1

我现在几乎就是这么做的。我正在使用 Theo.T 提到的包装器。

这是我的代码(大部分):

private function drawText(str:String, size:int = 16, px:int = 0, py:int = 0):void {
    var mc:MovieClip = new MovieClip();
    var tf:TextFormat = new TextFormat("Verdana", size, _textcolor);
    tf.align = "center";
    var _txt:TextField = new TextField();
    _txt.embedFonts = true;
    _txt.wordWrap = true;
    _txt.selectable = false;
    _txt.autoSize = TextFieldAutoSize.CENTER;
    _txt.antiAliasType = "advanced";
    _txt.defaultTextFormat = tf;
    _txt.width = _textwidth;
    _txt.text = str;
    _txt.x = -_txt.width / 2;
    mc.scaleX = mc.scaleY = _scalemin;
    mc.x = px;
    mc.y = py;
    mc.addChild(_txt);
    addChild(mc);
    startMove(mc);
}

private function moveText(e:Event):void {
    var mc:MovieClip = MovieClip(e.target);
    if (mc.scaleX >= _scalemax) {
        mc.scaleX = mc.scaleY = _scalemax;
    } else if (mc.y > _ymin) {
        mc.scaleX = mc.scaleY *= _scalegrow;
    }
    if (mc.alpha <= 0.1) {
        mc.removeEventListener(Event.ENTER_FRAME, moveText);
        mc.parent.removeChild(mc);
    }
}
于 2010-02-16T21:40:56.800 回答
0

我使用了上面发布的代码mga,它可以工作。我将整个内容发布在这里,因为我花了一点时间来弄清楚该怎么做。我注意到的是我不需要嵌入字体来让它工作。我想知道为什么?无论如何,这对我有用:

package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

public class LearningScrollingMain extends MovieClip {
    private var _scalemax:Number = 20;
    private var _ymin:Number = 10;
    private var _scalegrow:Number =1.05;
    private var _scalemin:Number=1;

    public function LearningScrollingMain() {
        drawText("The quick brown fox jumps over the lazy dog", 24, 400, 200);
    }

    private function drawText(str:String, size:int, px:int, py:int):void {
        var mc:MovieClip = new MovieClip();
        var tf:TextFormat = new TextFormat();
        tf.align = "center";
        tf.size=size;
        var _txt:TextField = new TextField();
        _txt.defaultTextFormat=tf;
//        _txt.embedFonts = true;
        _txt.wordWrap = false;
        _txt.selectable = false;
        _txt.autoSize = TextFieldAutoSize.CENTER;
        _txt.antiAliasType = "advanced";
        _txt.text = str;
        _txt.x = -_txt.width / 2;
        _txt.y = -_txt.height / 2;
        mc.scaleX = mc.scaleY = _scalemin;
        mc.x = px;
        mc.y = py;
        mc.addChild(_txt);
        addChild(mc);
        startMove(mc);
    }

    private function startMove(mc:MovieClip):void {
        mc.addEventListener(Event.ENTER_FRAME, moveText);
    }

    private function moveText(e:Event):void {
        var mc:MovieClip = MovieClip(e.target);
        if (mc.scaleX >= _scalemax) {
            mc.scaleX = mc.scaleY = _scalemax;
        } else if (mc.y > _ymin) {
            mc.scaleX = mc.scaleY *= _scalegrow;
        }
        if (mc.alpha <= 0.1) {
            mc.removeEventListener(Event.ENTER_FRAME, moveText);
            mc.parent.removeChild(mc);
        }
    }
}
}
于 2012-03-16T09:01:30.603 回答