You can use animations to create effects such as smooth transitions between viewpoints, or fade-in and fade-out effects.

The animation framework consists of two main components:

  • The animation manager provides global timing and bookkeeping.

  • The user implements Animations, and submits them for playback to the animation manager.

The class AnimationManager, a singleton, implements the animation manager.

The animation manager uses an internal clock to keep track of time. At every clock tick, the manager tells all running animations what the current time is, allowing the animations to take appropriate action.

When you submit an animation to the animation manager with the putAnimation method, it’s associated with a particular key. This is a convenience mechanism to prevent simultaneously running animations from interfering with each other. If you call putAnimation with the same key twice, the animation manager terminates the first animation associated with the object before starting the second one.

The Animation class defines Animations. It’s essentially a class that the manager notifies when the clock has ticked. When the animation starts, the manager calls the 'onStart' function. Afterward, to notify the animation, it calls the animation’s update function. It passes the current time to this function as an argument to determine the elapsed time relative to the time at which the animation started. What happens in the update function is up to the developer of the animation. Typically, some properties of an object — such as position, color, and transparency — are interpolated from an initial state to a target state over the duration of the animation.

An animation can specify its own duration. If an animation has reached the end of its duration, the 'onStop' function is called.

If you want to repeat an animation in a loop, you can configure that when you pass the Animation to the AnimationManager. A looping animation stops only if you explicitly remove it from the AnimationManager. To remove it, call removeAnimation with the key used to add the animation.