我正在尝试制作文本效果,文本字段的每一帧都会增加,并且不透明度会降低。我正在使用动态文本字段的scaleX和scaleY属性来放大,但它正在这样做,保持左注册点固定。我想让它径向向外扩大,或者固定中心点。谁能告诉我怎么做?
答案 0 :(得分:1)
textfield.x -= textfield.width /2;
textfield.y -= textfield.height /2;
如果x和y为0,这将有助于
答案 1 :(得分:1)
您可以轻松地为TextField
创建一个包装器(即包含TextField
的Sprite)以强制注册到中间位置。如果TextField是动态的,请确保autoSize
设置为LEFT
。此后,您只需将x/y
位置设置为-textField.width*.5/-textField.height*.5
即可。当然,缩放应该应用于父级。
答案 2 :(得分: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);
}
}
答案 3 :(得分: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);
}
}
}
}