スプライトを含むあらゆるものをアニメーション化するために使用できる汎用の Tween エンジンを Java で作成しました。ガベージ コレクションを回避するために実行時に何も割り当てないため、Android とゲーム用に最適化されています。さらに、トゥイーンはプールされるため、ガベージ コレクションはまったくありません。
完全なデモは、ここで Android アプリケーションとして、またはここで WebGL html ページ (Chrome が必要) として見ることができます!
インターフェースを実装してTweenAccessor
、Tween サポートをすべてのスプライトに追加するだけです。Sprite クラスを変更する必要さえありません。SpriteTweenAccessor
を実装するクラスを作成TweenAccessor<Sprite>
し、初期化時にエンジンに登録するだけです。GetStarted wiki ページを見てください;)
http://code.google.com/p/java-universal-tween-engine/

また、あらゆるアプリケーションに組み込むことができる視覚的なタイムライン エディターも構築しています。Flash オーサリング ツールと Expression Blend (Silverlight 開発ツール) に似たタイムラインが特徴です。
エンジン全体は詳細に文書化されており (すべての public メソッドとクラスには詳細な 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 アニメーションでこのエンジンを使用している人はすでにたくさんいます。