【问题标题】:actionscript 3, action after multiple tweening doneactionscript 3,多次补间完成后的动作
【发布时间】:2012-06-16 09:42:06
【问题描述】:

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

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

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

这种补间将在敌人的生命值变为零后发生, 我的意图是在动画之后,剪辑将从舞台上移除。

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

谢谢

【问题讨论】:

    标签: actionscript


    【解决方案1】:

    由于所有补间运行的持续时间都相同,您是否可以不只是将侦听器添加到最后一个补间,并且当处理程序执行时您会知道它们都已完成?

    或者你可以这样做:

    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 中为对象设置动画的标准,它允许您在一次调用中对同一对象的多个属性进行补间。

    【讨论】:

      【解决方案2】:

      Greensock 的 TweenLite 和 TimelineLite +1。

      使补间变得更干净、更容易。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-02
        • 2014-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-25
        • 1970-01-01
        相关资源
        最近更新 更多