Most visited

Recently visited

AnimationTransaction

public class AnimationTransaction
extends Object

java.lang.Object
   ↳ com.viro.core.AnimationTransaction


AnimationTransaction exposes a simple interface for animating properties of Viro objects. For example, to animate a Node to a new position, simply enclose the normal setPosition(Vector) call within an AnimationTransaction:

 AnimationTransaction.begin();
 AnimationTransaction.setAnimationDuration(5000);
 node.setPosition(new Vector(-2, 2.5f, -3));
 AnimationTransaction.commit();
You can also perform more complex animations, like changing the texture of a Material while rotating a Node. The initial texture will crossfade over to the new texture. We do this in the example below while using an "Ease Out" curve to decelerate the animation as it nears its end.

 AnimationTransaction.begin();
 AnimationTransaction.setAnimationDuration(5000);
 AnimationTransaction.setTimingFunction(AnimationTimingFunction.EaseOut);

 node.setRotation(new Vector(0, M_PI_2, 0));
 node.getGeometry().getMaterials().get(0).setDiffuseTexture(texture);

 AnimationTransaction.commit();
Finally, you can also chain animations or respond to the end of an animation by using a AnimationTransaction.Listener. In the snippet below, we move the position of a Node then, once that animation completes, we rotate the Node.

 AnimationTransaction.begin();
 AnimationTransaction.setAnimationDuration(5000);
 AnimationTransaction.setFinishCallback(new AnimationTransaction.Listener() {
     public void onFinished(final AnimationTransaction transaction) {
         AnimationTransaction.begin();
         node.setRotation(new Vector(0, M_PI_2, 0));
         AnimationTransaction.commit();
     }
 });
 node.setPosition(new Vector(-2, 2.5f, -3));
 AnimationTransaction.commit();

For an extended discussion on animation, refer to the Animation Guide.

Summary

Nested classes

interface AnimationTransaction.Listener

Callback interface for responding to the end of an AnimationTransaction

Public methods

static void begin()

Begin a new AnimationTransaction.

static AnimationTransaction commit()

Commit the AnimationTransaction, commencing all enclosed animations.

void dispose()

Release native resources associated with this AnimationTransaction.

void pause()

Pause this AnimationTransaction.

void resume()

Resume a paused AnimationTransaction.

static void setAnimationDelay(long delayMillis)

Set the time in seconds that we wait before the animations in this transaction start (after the AnimationTransaction is committed).

static void setAnimationDuration(long durationMillis)

Set the duration of all animations in this AnimationTransaction, in seconds.

static void setAnimationLoop(boolean loop)

Set to true to make this AnimationTransaction automatically loop to the beginning on finish.

static void setListener(AnimationTransaction.Listener listener)

Set a AnimationTransaction.Listener to invoke when the active transaction completes.

static void setTimingFunction(AnimationTimingFunction timingFunction)

Set an AnimationTimingFunction, which defines the pacing of the animation.

void terminate()

Terminate this AnimationTransaction.

Public methods

begin

void begin ()

Begin a new AnimationTransaction. All animatable properties set on the current thread after this call will be animated according to this new transaction. The animations will commence upon commit().

commit

AnimationTransaction commit ()

Commit the AnimationTransaction, commencing all enclosed animations.

Returns
AnimationTransaction The AnimationTransaction corresponding to this transaction.

dispose

void dispose ()

Release native resources associated with this AnimationTransaction.

pause

void pause ()

Pause this AnimationTransaction. All animations in the transaction will cease updating until resume() is invoked. The time remaining will remain in place as well. For example, if the animation is paused with 3 seconds remaining, the animation will have 3 seconds remaining when it is resumed.

resume

void resume ()

Resume a paused AnimationTransaction.

setAnimationDelay

void setAnimationDelay (long delayMillis)

Set the time in seconds that we wait before the animations in this transaction start (after the AnimationTransaction is committed).

Parameters
delayMillis long: The milliseconds to delay before beginning the transaction.

setAnimationDuration

void setAnimationDuration (long durationMillis)

Set the duration of all animations in this AnimationTransaction, in seconds.

Parameters
durationMillis long: The duration of the transaction, in milliseconds.

setAnimationLoop

void setAnimationLoop (boolean loop)

Set to true to make this AnimationTransaction automatically loop to the beginning on finish.

Parameters
loop boolean: True to loop back to the beginning when finished.

setListener

void setListener (AnimationTransaction.Listener listener)

Set a AnimationTransaction.Listener to invoke when the active transaction completes.

Parameters
listener AnimationTransaction.Listener: The AnimationTransaction.Listener to use for the current transaction.

setTimingFunction

void setTimingFunction (AnimationTimingFunction timingFunction)

Set an AnimationTimingFunction, which defines the pacing of the animation.

Parameters
timingFunction AnimationTimingFunction: The AnimationTimingFunction to use for the current transaction.

terminate

void terminate ()

Terminate this AnimationTransaction. This will force (snap) all values to their final value, and invoke the AnimationTransaction.Listener.

Hooray!