使用GreenSock补间alpha

时间:2013-02-04 18:16:45

标签: actionscript-3 alpha tween flash-cs6 greensock

尝试使用GreenSock补充AS3中graphics对象的alpha,但功能不起作用。尝试在2秒内补间从alpha 0到0.7。 fromTo();方法也不起作用。我不想,但我是否必须使用增量for循环来执行此操作? - 因为这不能让我控制补间的时间。

public function overlayBox():void {

    var overlaySquare:Sprite = new Sprite();

    overlaySquare.graphics.beginFill(0x00000);
    overlaySquare.graphics.drawRect(0, 0, displayRes, displayRes);
    overlaySquare.graphics.endFill();
    overlaySquare.x = xScreenPos;
    overlaySquare.y = yScreenPos;
    TweenMax.from(overlaySquare, 2, {autoAlpha:0});
    TweenMax.to(overlaySquare, 2, {autoAlpha:0.7});

    addChild(overlaySquare);
    trace("overlaySquare index: " + getChildIndex(overlaySquare));
}



编辑:我通过将TweenMax函数从上面替换为此来修复从alpha 0到0.7的淡入淡出:

overlaySquare.alpha = 0;
TweenMax.to(overlaySquare, 5, {alpha:0.7});

然而,当alpha补间与程序的其余部分一起运行时,它存在问题。一旦你看到它,补间“闪烁”并立即变为0.7(它看起来像是从0跳到“0.7”)。问题已被隔离到overlayBox();之后调用的函数。程序概述:使用加载器加载图像。在装载机内部,有一个myTimer.start();。这用于在加载图像后运行程序的其余部分。 overlayBox();是第一个跟随并运行良好的方法。下一个方法textAnimation();是打破它的原因,我不明白为什么:

public function textAnimation():void {

        //set text format
        textFormat.font = "Helvetica Neue Light";
        textFormat.size = 28;
        textFormat.bold = false;
        textFormat.color = 0xFFFFFF;
        //textFormat.letterSpacing = 5;

        //set text size
        var size18bold:TextFormat = new TextFormat();
        size18bold.size = 36;
        size18bold.bold = true;

        // pass text format
        textOne.defaultTextFormat = textFormat;
        textTwo.defaultTextFormat = textFormat;

        var xScreenPosStart:Number = xScreenPos + 440;
        var xScreenPosEnd:Number = xScreenPos - 300;

        textOne.text = "Blah blah blah";
        textOne.autoSize = TextFieldAutoSize.LEFT;
        textOne.x = xScreenPosStart;
        textOne.y = yScreenPos + 240;
        TweenMax.to(textOne, 14, {x:xScreenPosEnd, ease:SlowMo.ease.config(1, 0), repeat:-1});

        textTwo.text = "Blah blah blah";
        textTwo.autoSize = TextFieldAutoSize.LEFT;
        textTwo.x = xScreenPosStart;
        textTwo.y = yScreenPos + 140;
        TweenMax.to(textTwo, 12, {x:xScreenPosEnd, ease:SlowMo.ease.config(1, 0), repeat:-1, delay:4});

        //add to stage
        addChild(textOne);
        trace("textOne index: " + getChildIndex(textOne));
        addChild(textTwo);
        trace("textTwo index: " + getChildIndex(textTwo));

        textOne.setTextFormat(size18bold);

    }

2 个答案:

答案 0 :(得分:1)

不要使用TweenMax.from,而是手动设置alpha。

overlaySquare.alpha = 0;
TweenMax.to( overlaySquare, 2, { alpha : .7 } );

答案 1 :(得分:0)

为alpha提供初始值并仅使用tweenMax.To

你有没有激活自动alpha插件?如果没有,那么按

进行
import com.greensock.TweenLite; 
import com.greensock.plugins.TweenPlugin; 
import com.greensock.plugins.AutoAlphaPlugin; 

//activation is permanent in the SWF, so this line only needs to be run once.
TweenPlugin.activate([AutoAlphaPlugin]); 

如果您不需要自动alpha,那么只需使用alpha Property

我试过了:

private function _Show() : void {
    var overlaySquare:Sprite = new Sprite();
    overlaySquare.graphics.beginFill(0x00000);
    overlaySquare.graphics.drawRect(0, 0, 200, 200);
    overlaySquare.graphics.endFill();
    overlaySquare.x = 100;
    overlaySquare.y = 100;
    TweenMax.to(overlaySquare, 2, {alpha:0.7});

    addChild(overlaySquare);
    trace("overlaySquare index: " + getChildIndex(overlaySquare));
}

这很有效。