【问题标题】:Starling framework AS3 Fade-Out Image on Removal Timer not working?Starling 框架 AS3 Fade-Out Image on Removal Timer 不工作?
【发布时间】:2013-12-09 07:19:57
【问题描述】:

我试图让我的徽标图像在 onLogoComplete 计时器停止并调用 onCompleteNukerLogo 计时器以在徽标图像上运行 Starling 动画 fadeTo 时淡出。但是,我无法弄清楚为什么在调用计时器时图像没有淡出。 FlashBuilder 中没有错误,我眼中的代码似乎是正确的。

我正在努力实现的目标。标志淡入,暂停一秒钟让观众看到它,然后调用kill-timers(删除计时器),当最后一个计时器运行时,它应该淡出标志,然后删除孩子。但是,它只是在运行,然后删除徽标图像而不淡出。

这是我的代码。我究竟做错了什么?或者,Starling 是否不可能同时进行淡入和淡出?

package screens
{
import flash.events.TimerEvent; 
import flash.utils.Timer;
import screens.DesktopScreenTitle;
//
import starling.display.Button;
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;
import starling.animation.Juggler;

public class StudioScreen extends Sprite
{
    //--Images
    private var bg:Image;
    private var logo:Image;
    //--Tweens
    private var logoTween:Tween;
    //--Timers
    private static var callLogoKill:Timer;
    private static var nukeLogo:Timer;

    public function StudioScreen()
    {
        super();
        this.addEventListener(starling.events.Event.ADDED_TO_STAGE, stageSetup);
    }
    //-------------------------------------------------------------------------|
    //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //##setup stage------------------------------------------------------------|
    private function stageSetup(event:Event):void 
    {
        drawTitle();
        callLogoKill = new Timer( 5000 );
        callLogoKill.addEventListener( TimerEvent.TIMER, onLogoComplete);
        callLogoKill.start();
    }

    public function onLogoComplete(e:TimerEvent) {
        callLogoKill.stop(); 
        nukeLogo = new Timer ( 1000 );
        nukeLogo.addEventListener( TimerEvent.TIMER, onCompleteNukeLogo )
        nukeLogo.start();
    }

    public function onCompleteNukeLogo(e:TimerEvent) {
        logoTween = new Tween(logo, 1, Transitions.EASE_OUT);
        logoTween.fadeTo(0);
        Starling.juggler.add(logoTween);
        this.removeChild(logo);
        nukeLogo.stop();
    }

    private function drawTitle():void {
        drawBG();
        drawLogo();
    }

    private function drawLogo():void {
        //Draw Logo
        logo = new Image(Assets.getTexture("logoJoyhype"));
        logo.x = (stage.stageWidth - logo.width) /2;
        logo.y = (stage.stageHeight - logo.height) /2;
        logo.alpha = 0;
        this.addChild(logo);
        //--Tween Logo
        logoTween = new Tween(logo, 1, Transitions.EASE_IN);
        logoTween.fadeTo(1);
        Starling.juggler.add(logoTween);
    }

    private function drawBG():void {
        bg = new Image(Assets.getTexture("yellowBG"));
        this.addChild(bg);
    }

    public function nuke() 
    {
        this.removeChild(bg);
    }
}
}

谢谢!

【问题讨论】:

    标签: actionscript-3 starling-framework


    【解决方案1】:

    我看到您在启动淡出的同时从显示列表中删除了徽标:

    你的代码:

    public function onCompleteNukeLogo(e:TimerEvent) {
        logoTween = new Tween(logo, 1, Transitions.EASE_OUT);
        // you start fade out here
        logoTween.fadeTo(0);  
        Starling.juggler.add(logoTween);
        // you remove logo here ?
        this.removeChild(logo);
        nukeLogo.stop();
    }
    

    也许可以试试:

    public function onCompleteNukeLogo(e:TimerEvent) 
    {
        logoTween = new Tween(logo, 1, Transitions.EASE_OUT);
        // add on complete callback
        logoTween.onComplete = oncompleteFadeOut;
        logoTween.fadeTo(0);  
        Starling.juggler.add(logoTween);
        nukeLogo.stop();
    }
    /** called at the end of the fadeOut of the logo **/
    public function oncompleteFadeOut():void
    {
        // remove logo
        this.removeChild(logo);
    }
    

    【讨论】:

    • 噢,我明白了。我什至在它有机会做我想让它做的事情之前就把它杀死了。非常感谢!前几天我刚开始学习 Starling。很多漂亮的东西要学习/修补!非常感谢。 :)
    猜你喜欢
    • 2011-12-24
    • 2011-08-26
    • 2014-12-10
    • 1970-01-01
    • 2015-08-31
    • 2012-12-03
    • 2012-07-22
    • 2012-12-17
    • 1970-01-01
    相关资源
    最近更新 更多