当onLogoComplete计时器停止并调用onCompleteNukerLogo计时器在徽标图像上运行Starling动画fadeTo时,我正试图让我的徽标图像淡出。然而,我不明白为什么当计时器被调用时,图像没有消失。FlashBuilder中没有错误,在我看来代码似乎是正确的。
我正在努力实现的目标。标志会淡入,暂停一秒钟让观众看到,然后调用终止计时器(删除计时器),当最后一个计时器运行时,它应该淡出标志,然后删除孩子。然而,它只是运行,然后删除徽标图像而不淡出。
这是我的密码。我做错了什么?还是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);
}
}
}
谢谢!
正如我所看到的,你在启动淡出的同时从显示列表中删除了徽标:
您的代码:
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);
}