2017-05-22 29 views
1

我試圖將卡移動到我的用戶他們是三個成員在這裏我有九張卡在這裏我的代碼below.I使用tweenlite移動前三張卡成功移動然後其餘的卡如何移動到用戶。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}); 

} 

任何人都知道請詳細說明這一個。

回答

2

沒有必要爲每個卡創建的獨立的代碼,它們都是一樣的。創建 + X + Ÿ條目的陣列,並與項目合作。

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}); 
} 
+0

真的很非常感謝你對它的好作品 –

+0

很棒的回答Organis。在這種情況下如何使用TimeLineLite(https://greensock.com/timelinelite-as)?對動畫排序來說,這可能是最好的選擇。乾杯。 –

+0

@GurtejSingh不知道,對不起。我有我自己的補間和場景播放類,所以我不打擾第三方框架。 – Organis