我在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