【问题标题】:Tweenlite in multiple objects多个对象中的 Tweenlite
【发布时间】:2017-10-22 03:57:56
【问题描述】:

我试图将卡片移动给我的用户,他们是三个成员,我有九张卡片,下面是我的代码。我已经使用 tweenlite 将前三张卡片移动成功,然后其余卡片如何移动给用户。

import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;

 click_mc.addEventListener(MouseEvent.CLICK, UserOne);



function UserOne(evt:MouseEvent):void
{

    TweenMax.to(joker_mc, .5, { x:598.25, y:164.45 , onComplete:UserTwo} );     
}

function UserTwo():void
{
    TweenLite.to(king_mc, .5, { x:316.50, y:267.90, onComplete:UserThree} );

}

function UserThree():void
{
    TweenLite.to(queen_mc, .5, { x:39, y:172} );

}

谁知道请详细说明一下。

【问题讨论】:

    标签: actionscript-3 flash actionscript air


    【解决方案1】:

    无需为每张卡片创建单独的代码,它们都是相似的。创建一个包含 card + x + y 条目的数组,然后使用这些条目。

    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.events.MouseEvent;
    
    var currentEntry:int = -1;
    var aList:Array =
    [
        {card:joker_mc, x:598.25, y:164.45},
        {card:king_mc,  x:316.50, y:267.90},
        {card:queen_mc, x:39, y:172},
    
        // ...
        // and so on
    ];
    
    click_mc.addEventListener(MouseEvent.CLICK, onClick);
    
    function onClick(e:MouseEvent):void
    {
        // Unsubscribe to avoid the mess with second click.
        click_mc.removeEventListener(MouseEvent.CLICK, onClick);
    
        // Start process.
        moveNext();
    }
    
    function moveNext():void
    {
        currentEntry++;
    
        // Stop the process if all the cards have been moved.
        if (currentEntry >= aList.length) return;
    
        // Get the entry.
        var anEntry:Object = aList[currentEntry];
    
        // Move the card.
        TweenLite.to(anEntry['card'], .5, {x:anEntry['x'], y:anEntry['y'], onComplete:moveNext});
    }
    

    【讨论】:

    • 很好的答案Organis。在这种情况下使用 TimeLineLite (greensock.com/timelinelite-as) 怎么样?这可能是用于序列动画的最佳选择。干杯。
    • @GurtejSingh 不知道,抱歉。我有自己的补间和场景播放类,所以我不用担心第三方框架。
    猜你喜欢
    • 2012-01-05
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-07
    • 1970-01-01
    相关资源
    最近更新 更多