当onLogoComplete计时器停止并且调用onCompleteNukerLogo计时器以在徽标图像上运行Starling动画fadeTo时,我试图让我的徽标图像淡出。但是,我无法弄清楚为什么在调用定时器时图像不会淡出。 FlashBuilder中没有错误,我眼中的代码似乎是正确的。
我正在努力实现的目标。徽标淡入,暂停一秒钟让观众看到它,然后调用kill-timers(删除计时器),当最后一个计时器运行时,它应该将徽标淡出然后移除孩子。但是,它只是运行然后删除徽标图像而不淡出。
这是我的代码。我究竟做错了什么?或者,这对于Starling来说不可能做fadeIn和fadeOut吗?
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);
}
}
}
谢谢!
答案 0 :(得分: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);
}