1

私はゲーム開発の初心者です。現在、学習目的でシューティングゲームを扱っています。質問があります、

私のゲームでは、3 つのトゥイーン アニメーションを作成しました。

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 イベントを適用しようとしましたが、そうすると 3 つのリスナーを作成する必要があります (10 個のトゥイーンを作成する場合は問題になります)。

ありがとうございました

4

2 に答える 2

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 の TweenLiteを検討することもできます。これは、Flash でオブジェクトをアニメーション化するためのほぼ標準であり、1 回の呼び出しで同じオブジェクトの複数のプロパティをトゥイーンできます。

于 2012-06-17T22:56:01.130 に答える
0

Greensock の TweenLite と TimelineLite の場合は +1。

すべてのトゥイーンをよりクリーンで簡単にします。

于 2014-10-20T21:11:25.747 に答える