|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.umd.cs.jazz.animation.ZAnimation
ZAnimation and its subclasses provide the central programming interface to the animation system. Most animations consist of a source property, a destination property and a target object that is normally something in the Jazz scene graph. The animation interpolates between its source and destination property over time, applying the intermediate values to its target. For a concrete look at this behavior see ZColorAnimation.
Each ZAnimation has a ZAlpha object that it uses to determine when it should start, when it should finish, and how it should interpolate between its source and destination values.
When creating most animations three decisions need to be made.
Once an animation has been constructed the method play
must be called so that the animation gets scheduled with the current ZAnimationScheduler. Once the scheduler determines (by using the animations ZAlpha and ZNextFrameCondition) that the next frame of the animation should be animated it calls animateFrameForTime
on the animation. In this method the animation performs all animation activities, finishing that method implementation by scheduling its next frame if it wishes to continue animating.
Here is a simple animation example. It uses a transform animation to animate a square across the screen.
ZRectangle aRect = new ZRectangle(0, 0, 100, 100);
ZVisualLeaf aLeaf = new ZVisualLeaf(aRect);
// The animation will apply to the transform group decorating the aLeaf node.
ZTransformGroup aTarget = aLeaf.editor().getTransformGroup();
canvas.getLayer().addChild(aTarget);
// Create a new ZAlpha that will run from the current time for 1.5 seconds.
// This alpha will change linearly; see the ZAlpha class to learn how to create
// slow in slow out animation effects.
ZAlpha alpha = new ZAlpha(1, 1500);
// Create the ZTransformAnimation with its source and destination values. Here
// we choose to animate the target from its current transform, to the identity transform
// translated by 300, 300.
AffineTransform souceTransform = aTarget.getTransform();
AffineTransform destinationTransform = AffineTransform.getTranslateInstance(300, 300);
ZTransformAnimation aTransformAnimation = new ZTransformAnimation(souceTransform, destinationTransform);
// Set the target of the animation.
aTransformAnimation.setTransformTarget(aTarget);
// Set the alpha value for the animation. This animation will start immediately,
// and run for 1.5 seconds.
aTransformAnimation.setAlpha(alpha);
// Start the animation by registering it with the ZAnimationScheduler.
aTransformAnimation.play();
ZAlpha
Constructor Summary | |
ZAnimation() Construct a new ZAnimation. |
|
ZAnimation(ZAlpha aAlpha) Construct a new ZAnimation. |
Method Summary | |
protected void |
animateFrameForTime(long aTime) Animate one frame of this animation at the specified time, and schedule a new frame to be animated if the alpha object that is scheduling this animation has not yet finished. |
void |
animationRateByElapsedFrames(long aFramesCount) This method makes the animation schedule its frames by elapsed frames. |
void |
animationRateByElapsedTime(long aElapsedTime) This method makes the animation schedule its frames by elapsed time. |
void |
animationRateByNextFrame() Make it so that that this animation will be animated on every frame that the ZAnimationScheduler runs. |
protected void |
animationStarted() Template method that is called when the first frame of the animation is animated after play has been called. |
protected void |
animationStopped() Template method that is called when the animation is temporarily stopped with the stop method or when the animation finishes. |
ZAlpha |
getAlpha() Return the alpha object used to determine the animations start and finish time, and to generate any alpha values that it needs when interpolating between values. |
boolean |
isStopped() Return true if the animation has been stopped. |
void |
play() Schedule this animation with the ZAnimationScheduler. |
protected void |
scheduleNextFrame() Schedule the next frame of the animation. |
protected void |
scheduleNextFrame(ZNextFrameCondition aCondition) Schedules this animation with the given condition with the ZAnimationScheduler. |
void |
setAlpha(ZAlpha aAlpha) Set the alpha object used to determine the animations start and finish time, and to generate alpha values that it needs when interpolating between values. |
void |
setStartedRunnable(java.lang.Runnable aRunnable) Specify a Runnable that will be executed when the animation is started.. |
void |
setStoppedRunnable(java.lang.Runnable aRunnable) Specify a Runnable that will be executed when the animation is stopped.. |
void |
stop() Temporarily or permanently stop the animation. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ZAnimation()
public ZAnimation(ZAlpha aAlpha)
aAlpha
- the alpha parameter determines the animations start and finish time, and generates any alpha values needed by the animation to interpolate between values.Method Detail |
protected void animateFrameForTime(long aTime)
ZAnimation subclasses should override this method and perform all animation code from with it.
public void animationRateByElapsedFrames(long aFramesCount)
animation.animationRateByElapsedFrames(5)
.
aFramesCount
- the number of frames to wait until the next frame of this animation is animated.public void animationRateByElapsedTime(long aElapsedTime)
animation.animationRateByElapsedTime(1000)
.
aElapsedTime
- the amount of time to wait before animating the next frame of the animation, specified in milliseconds.public void animationRateByNextFrame()
protected void animationStarted()
play
has been called.
protected void animationStopped()
stop
method or when the animation finishes.
public ZAlpha getAlpha()
public boolean isStopped()
play
method.
public void play()
protected void scheduleNextFrame()
animateFrameForTime
. It creates a new ZNextFrameCondition and schedules this animation with that condition on the ZAnimationScheduler.
protected void scheduleNextFrame(ZNextFrameCondition aCondition)
public void setAlpha(ZAlpha aAlpha)
aAlpha
- the alphapublic void stop()
play
method.
public void setStartedRunnable(java.lang.Runnable aRunnable)
public void setStoppedRunnable(java.lang.Runnable aRunnable)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |