An Animator can be attached to one or more {@link GLAutoDrawable}s to drive their display() methods in a loop.
The Animator class creates a background thread in which the calls to display()
are performed. After each drawable has been redrawn, a brief pause is performed to avoid swamping the CPU, unless {@link #setRunAsFastAsPossible} has been called.
Most of the methods here are simle getters/setters for the properties used by Animator. Typical animations will simply use one of the two constructors (depending on whether you are constructing a repeating animation), optionally call any of the set*
methods to alter any of the other parameters, and then call start() to run the animation. For example, this animation will run for 1 second, calling your {@link TimingTarget} with timing events when the animation is started,running, and stopped:
Animator animator = new Animator(1000, myTarget); animator.start();The following variation will run a half-second animation 4 times, reversing direction each time:
Animator animator = new Animator(500, 4, RepeatBehavior.REVERSE, myTarget); animator.start();More complex animations can be created through using the properties in Animator, such as {@link Animator#setAcceleration acceleration} and {@link Animator#setDeceleration}. More automated animations can be created and run using the {@link org.jdesktop.animation.timing.triggers triggers}package to control animations through events and {@link org.jdesktop.animation.timing.interpolation.PropertySetter} to handle animating object properties.
Animator animator = new Animator.Builder().setDuration(500, TimeUnit.MILLISECONDS).setRepeatCount(4).addTarget(myTarget).build(); animator.start();More complex animations can be created through the use of the complete set of properties in {@link Animator.Builder}.
This class provides a useful "debug" name via {@link Builder#setDebugName(String)} and {@link #getDebugName()}. The debug name is also output by {@link #toString()}. This feature is intended to aid debugging.
Instances can be started again after they complete, however, ensure that they are not running, via ! {@link #isRunning()} or {@link #await()}, before {@link #start()} or {@link #startReverse()} is called. Even if yousuccessfully invoked {@link #stop()} or {@link #cancel()} it can take sometime for all the calls to registered {@link TimingTarget}s to complete. Use of {@link #await()} is far more efficient than polling the state of theanimation with {@link #isRunning()}.
This class is thread-safe. @author Chet Haase @author Tim Halloran @see Builder
The Animator class provides the basic functionality to display the state of an animation and to step that animation forward at a regular frame rate.
This class extends JPanel, to provide a component upon which the animation is drawn. It also implements Runnable in order to provide a thread which periodically steps the state of the animation to the next frame and calls repaint() to persuade the event dispatch thread to paint that frame.
The state of the animation is actually managed by an aggregated object of a class which implements the {@link Animatable} interface. This providesmethods by which the state may be stepped or painted.
To ensure thread safety, the methods of this class, except for run()
which shouldn't be called directly anyway, should only be called from within the event dispatch thread.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|