Universal Tween Engine
The Universal Tween Engine enables the interpolation of every attributes from any object in any Java project (being Swing, SWT, OpenGL or even console-based). A tween is a static animation running for a fixed amount of time. Therefore, tweens are perfect candidates to animate your UIs, splash screens, and all the static animations of your characters. A tween can animate anything: position, rotation, opacity, color, scale, etc. The only limitation of the tween engine is your imagination.
- Android application
- Desktop application (stand-alone executable)
- HTML5 page (requires a WebGL enabled browser, like Chrome)
- Zero allocation! Use your project safely on Android without fearing the garbage collector!
- Supports every interpolation function defined by Robert Penner: http://www.robertpenner.com/easing/
- Can be used with any object. You just have to implement the TweenAccessor interface when you want interpolation capacities.
- Every attributes can be interpolated. The only requirement is that what you want to interpolate can be represented as a float number.
- One line is sufficient to create and start a simple interpolation.
- Tweens can be easily sequenced thanks to Timelines.
- Tweens can act on more than one value at a time, so a single tween can change the whole position (X and Y) of a sprite for instance !
- Tweens and Timelines can be repeated, with a yoyo style option.
- Many callbacks can be specified (when tweens or timelines complete, start, end, etc.).
- Simple timers can be built with Tween.call().
- Source code extensively documented!
- Wiki documentation to get you started!
The engine is mainly divided into Tweens and Timelines.
Tweens are small one-line statements that let you start the animation of one or multiple attributes of an object. Better than a thousand lines of text, take a look at the following demo applet (link on the right). Don’t hesitate to change the easing function, and to add repetitions to your animation.
In this demonstration, we only use tween to animate the position of an object. However, when using the Tween Engine, you describe what you want to animate, so everything is possible. To start a tween, only thing needed is:
// Animation of an object position to the coordinates (100,200), in one second Tween.to(myobject, Type.POSITION, 1.0f).target(100, 200).start(myManager);
Many options are available to customize the animation:
Tween.to(myobject, Type.POSITION, 1.0f) .targetRelative(10, -20) // the target can be relative to the current values .delay(2.5f) // a delay can be specified .ease(Quad.OUT) // the easing function can be modified .repeat(2, 0.5f) // repetitions are possible .repeatYoyo(2, 0.5f) // yoyo repetitions too (one play forward, the other backward, etc) .setUserData(obj) // custom objects can be attached .setCallback(cb) // callbacks can be specified to get notified of the completion .setCallbackTriggers(...) // callbacks can be launched on many events, not just completion .start(myManager);
A tween is based on precise timings, as follows:
Callbacks are very important, and let you trigger actions on precise events. There are callbacks for forward playing, and for backward playing:
Creating sequences is easy, just stack
.push() calls! You can also nest timelines into other timelines.
Timeline.createSequence() .push(Tween.set(...)) // First, set all objects to their initial positions .push(Tween.set(...)) .push(Tween.set(...)) .pushPause(1000) // Wait 1 second .push(Tween.to(...)) // Move the objects around, one after the other .push(Tween.to(...)) .push(Tween.to(...)) .beginParallel() // Move them all at the same time now .push(Tween.to(...)) .push(Tween.to(...)) .push(Tween.to(...)) .end() .repeatYoyo(2, 500) // repeat the whole sequence 2 times .start(myManager); // and finally start it!
The options of timelines are the same as the ones for tweens, including repetitions and callbacks! What was possible for tweens is also possible for timelines.
Download binaries and source code
The project is fully open-source, and currently hosted at Google Code using a Mercurial repository. Each time a revision is considered stable, it is released as a binary package.
Project page: http://code.google.com/p/java-universal-tween-engine/
Download page: http://code.google.com/p/java-universal-tween-engine/downloads/list
A detailed example is provided in the project wiki:
Also, you may want to take a look at the source code of the demo:
Sources for the library are shared within the zip file. Linking to them in your favorite IDE (eclipse, netbeans, idea) will let you access the javadocs directly from the editor itself.
If you spotted a bug, or have a great improvement idea, feel free to submit it to the Issue Tracker.
For any other information, there is a dedicated forum for you.