动作脚本3,多次完成补间后的动作

时间:2012-06-16 09:42:07

标签: actionscript

我是游戏开发的新手,现在我正在使用射击游戏进行学习。 我有一个问题,

在我的游戏中我创建了三个补间动画:

var myTween:Tween = new Tween(this, "scaleX", Back.easeIn, 1.2, 0, 10);
var myTween2:Tween = new Tween(this, "scaleY", Back.easeIn, 1.2, 0, 10);
var myTween3:Tween = new Tween(this, "alpha", None.easeIn, 1, 0, 10);

此敌人将在敌人的健康状况变为零后发生, 我的意图是在动画之后,剪辑将从舞台上删除。

我的问题是,有没有办法知道所有这些补间已经完成?我尝试为每个补间应用TweenEvent.MOTION_FINISH事件,但如果我这样做,我必须创建三个侦听器(如果我想创建十个补间,这将是有问题的。)

谢谢

2 个答案:

答案 0 :(得分:0)

由于所有补间都运行相同的持续时间,你不能只是将你的监听器添加到最后一个补间,当处理程序执行时你会知道它们已经完成了吗?

或者你也可以这样做:

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.motion.easing.Back;
import fl.transitions.easing.None;

// Populate an array with the tweens
var tweens:Array = [];
tweens.push(new Tween(this, "scaleX", Back.easeIn, 1.2, 0, 10));
tweens.push(new Tween(this, "scaleY", Back.easeIn, 1.2, 0, 10));
tweens.push(new Tween(this, "alpha", None.easeIn, 1, 0, 10));

// Finished tweens count
var finishedCount:int = 0;

// Loop through all the tweens and add a handler for the motion finished event
for (var i:int = 0; i < tweens.length; i ++)
{
    // Each of the tweens motion finished event can be assigned to the same handler
    Tween(tweens[i]).addEventListener(TweenEvent.MOTION_FINISH, motionFinishedHandler);
}

function motionFinishedHandler(e:TweenEvent):void
{
    // Good practice to remove the event listener when it is no longer needed
    e.target.removeEventListener(TweenEvent.MOTION_FINISH, motionFinishedHandler);

    // Increment the count and test whether it equals the number of tweens
    if (++ finishedCount == tweens.length)
        trace("Finished");
}

您可能还需要考虑Greensock's TweenLite,它几​​乎是Flash中对象动画的标准,它允许您在单个调用中补间同一对象的多个属性。

答案 1 :(得分:0)

为Greensock的TweenLite&amp; TimelineLite。

让一切变得更干净,更轻松。