我在java中构建了一个通用的Tween引擎,您可以使用它来为任何东西(包括您的精灵)制作动画。它针对Android和游戏进行了优化,因为它不会在运行时分配任何内容,以避免垃圾收集。而且,Tweens被集中在一起,所以真的:根本没有垃圾回收!
您可以看到一个完整的演示here作为Android应用程序,或here作为WebGL HTML页面(需要Chrome)!
您只需实现TweenAccessor
接口即可将Tween支持添加到所有的精灵中。您甚至不需要更改Sprite类,只需创建一个SpriteTweenAccessor
类,该类实现TweenAccessor<Sprite>
,并在初始化时将其注册到引擎。只要有一个看看GetStarted wiki page)
http://code.google.com/p/java-universal-tween-engine/
我还建立能够被嵌入到任何应用程序的可视化时间轴编辑器。它将具有类似于Flash创作工具和Expression Blend(Silverlight开发工具)的时间表。
整个引擎大量记录(所有公共方法和类都有详细的javadoc),语法与Flash世界中使用的Greensock的TweenMax/TweenLite引擎非常相似。请注意,它支持每个Robert Penner缓动方程。
// Arguments are (1) the target, (2) the type of interpolation,
// and (3) the duration in seconds. Additional methods specify
// the target values, and the easing function.
Tween.to(mySprite, Type.POSITION_XY, 1.0f).target(50, 50).ease(Elastic.INOUT);
// Possibilities are:
Tween.to(...); // interpolates from the current values to the targets
Tween.from(...); // interpolates from the given values to the current ones
Tween.set(...); // apply the target values without animation (useful with a delay)
Tween.call(...); // calls a method (useful with a delay)
// Current options are:
yourTween.delay(0.5f);
yourTween.repeat(2, 0.5f);
yourTween.repeatYoyo(2, 0.5f);
yourTween.pause();
yourTween.resume();
yourTween.setCallback(callback);
yourTween.setCallbackTriggers(flags);
yourTween.setUserData(obj);
// You can of course chain everything:
Tween.to(...).delay(1.0f).repeat(2, 0.5f).start();
// Moreover, slow-motion, fast-motion and reverse play is easy,
// you just need to change the speed of the update:
yourTween.update(delta * speed);
当然,没有吐温引擎将是不完整的提供了一个方法来建立强大的序列:)
Timeline.createSequence()
// First, set all objects to their initial positions
.push(Tween.set(...))
.push(Tween.set(...))
.push(Tween.set(...))
// Wait 1s
.pushPause(1.0f)
// Move the objects around, one after the other
.push(Tween.to(...))
.push(Tween.to(...))
.push(Tween.to(...))
// Then, move the objects around at the same time
.beginParallel()
.push(Tween.to(...))
.push(Tween.to(...))
.push(Tween.to(...))
.end()
// And repeat the whole sequence 2 times
// with a 0.5s pause between each iteration
.repeatYoyo(2, 0.5f)
// Let's go!
.start();
我希望你相信:)有很多人已经在使用引擎在他们的游戏或android UI动画。
哇,这太棒了,谢谢。 – 2011-04-14 13:21:17
我刚刚更新了一下说明,因为从我第一次写答案开始,引擎已经取得了巨大的进步:) – 2012-05-31 14:47:29
@AurélienRibon,它是否提供从一个精灵到另一个精灵的动画? – 2014-05-21 21:59:36