【问题标题】:TweenLite Design PatternTweenLite 设计模式
【发布时间】:2011-11-30 05:31:00
【问题描述】:

只是好奇。 TweenLite/TweenMax 是一个非常常见的动画库,我想知道有人会如何对 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;

【问题讨论】:

    标签: flash actionscript gsap


    【解决方案1】:

    在它们传递关联数组而不是调用实际函数的地方,这是神奇的容器反模式:http://c2.com/cgi/wiki?MagicContainer。这被认为是一个坏主意,因为您确实应该调用特定函数而不是构造疯狂的参数包。

    【讨论】:

    • 而且,TweenLite 仍然很受欢迎并被广泛使用。这表明我猜,制作成功的软件并不总是需要遵循设计模式。
    • @LarsBlåsjö,是的......虽然使用该模式的一部分是试图绕过语言的限制,所以我不会过多地责怪他们。
    • @LarsBlåsjö ,tweenlite 是这样设计的,因为 Flash 中的对象是动态的,并且它不直接针对显示对象,您可以在任何对象上使用 tweenlite 并通过数字插入该对象的任何属性帧或时间。实际上,我可以看到该模式的唯一负面影响可能是保留关键字冲突的可能性更高,并且会牺牲一些效率(尽管 tweenlite 的运行速度比大多数补间引擎快得多)。我问这个问题是因为我真的很喜欢它的设计方式!
    • 更糟糕的是,TweenLite 使用静态方法和函数,并迫使您混合实例和静态,因为它们都没有提供所有功能。
    猜你喜欢
    • 1970-01-01
    • 2011-10-20
    • 2013-08-27
    • 2012-04-14
    • 2010-12-28
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多