0

尝试graphics使用 GreenSock 对 AS3 中对象的 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 tween 会出现问题。补间“闪烁”并立即变为 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);

    }
4

2 回答 2

1

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

overlaySquare.alpha = 0;
TweenMax.to( overlaySquare, 2, { alpha : .7 } );
于 2013-02-04T19:22:08.820 回答
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 属性

我试过这个:

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));
}

这行得通。

于 2013-02-04T18:20:27.167 回答