Tweenlite在多个对象中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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} );
}
有人知道请详细说明这个。
答案
没有必要为每张卡创建单独的代码,它们都是相似的。创建一个带有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});
}
以上是关于Tweenlite在多个对象中的主要内容,如果未能解决你的问题,请参考以下文章