TweenLite 设计模式

发布于 12-08 09:39 字数 1903 浏览 0 评论 0原文

只是好奇。 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;

Just curious. TweenLite/TweenMax is a very common animation library, and I was wondering how someone would classify the design pattern used in TweenLite.
For those of you unfamiliar, here's some example code from their website:

//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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等数载,海棠开2024-12-15 09:39:19

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

Where they are passing around associative arrays rather then calling actual functions, it is the magic container anti-pattern: http://c2.com/cgi/wiki?MagicContainer. It's considered a bad idea because you should really be calling specific functions not constructing crazy bags of parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文