2011-10-03 24 views
1

只是好奇。 TweenLite/TweenMax是一個非常常見的動畫庫,我想知道如何分類TweenLite中使用的設計模式。 對於那些你不熟悉,這裏是從他們的網站一些示例代碼:TweenLite設計模式

//import the GreenSock classes 
import com.greensock.*; 
import com.greensock.easing.*; 

//tween the MovieClip named "mc" to an alpha of 0.5 over the course of 3 seconds 
TweenLite.to(mc, 3, {alpha:0.5}); 

//scale myButton to 150% (scaleX/scaleY of 1.5) using the Elastic.easeOut ease for 2  seconds 
TweenLite.to(myButton, 2, {scaleX:1.5, scaleY:1.5, ease:Elastic.easeOut}); 

//tween mc3 in FROM 100 pixels above wherever it is now, and an alpha of 0. (notice the vars object defines the starting values instead of the ending values) 
TweenLite.from(mc3, 1, {y:"-100", alpha:0}); 

//after a delay of 3 seconds, tween mc for 5 seconds, sliding it across the screen by changing its "x" property to 300, using the Back.easeOut ease to make it shoot past it and come back, and then call the onFinishTween() function, passing two parameters: 5 and mc 
TweenLite.to(mc, 5, {delay:3, x:300, ease:Back.easeOut, onComplete:onFinishTween, onCompleteParams:[5, mc]}); 
function onFinishTween(param1:Number, param2:MovieClip):void { 
trace("The tween has finished! param1 = " + param1 + ", and param2 = " + param2); 
} 

//call myFunction() after 2 seconds, passing 1 parameter: "myParam" 
TweenLite.delayedCall(2, myFunction, ["myParam"]); 

//use the object-oriented syntax to create a TweenLite instance and store it so we can reverse, restart, or pause it later. 
var myTween:TweenLite = new TweenLite(mc2, 3, {y:200, alpha:0.5, onComplete:myFunction}); 

//some time later (maybe in by a ROLL_OUT event handler for a button), reverse the tween, causing it to go backwards to its beginning from wherever it is now. 
myTween.reverse(); 

//pause the tween 
myTween.pause(); 

//restart the tween 
myTween.restart(); 

//make the tween jump to exactly its 2-second point 
myTween.currentTime = 2; 

回答

0

當他們繞過關聯數組而不是調用實際的功能,它是一個神奇的容器反模式:http://c2.com/cgi/wiki?MagicContainer。這被認爲是一個壞主意,因爲你真的應該調用特定的功能而不是構建瘋狂的參數。

+0

而且,TweenLite仍然很受歡迎並且被廣泛使用。看來,下面的設計模式並不總是需要成功的軟件,我想。 –

+0

@LarsBlåsjö,是的......雖然使用該模式的一部分是試圖繞過語言的限制,所以我不會責怪他們太多。 –

+0

@LarsBlåsjö,tweenlite是這樣設計的,因爲flash中的對象是動態的,並且它不直接針對displayobjects,你可以在任何對象上使用tweenlite並通過一定數量的幀或時間插入對象的任何屬性。真的,我可以看到的唯一的消極因素是預留關鍵字衝突的可能性較高,並且效率有所降低(儘管Tweenlite的運行速度比大多數補間引擎快)。我問這個問題是因爲我真的很喜歡它的設計! – K2xL