Java Reference
In-Depth Information
Usage of the SimpleInterpolator class requires the implementation of function
curve(t:Number):Number , which is expected to emit the target value for a given t .
The code snippet for this recipe implements the curve function where:
F If the t greater than 1 - attraction , the function snaps to the end value
F If t is decreasing and goes below attraction, it snaps to the start value
F Otherwise, t progresses linearly
In our example, we use our magnetic interpolator in the KeyFrame instance to animate
the displacement of the Circle instance along the x-axis over a period of two seconds.
As the animation engine interpolates the location of the circle ( circ.centerX ) using the
MagneticInterpolator instance, it will snap the end position of 375 when the time ratio
t slides beyond the attraction property. When the animation is running in reverse, the
interpolator snaps to 0 when t is less than attraction .
See also
F Introduction
F Building animation with the KeyFrame API
F Morphing shapes with the DelegateShape class
Morphing shapes with the DelegateShape
class
You have seen these cool effects in movies and TV shows where an object smoothly transition
from its current shape to another shape. The transition is known as morphing and you can
easily achieve the same effect in JavaFX. In this recipe, we will explore how to use animation
sequences and the DelegateShape class to morph shapes.
Getting ready
This recipe uses animation concepts presented in previous recipes. If you are not familiar with
how to create animation sequences, review the recipe Building animation with the KeyFrame
API . This recipe also uses the DelegateShape class, which is found in package javafx.
scene.shape . This class, as you will see, can be used to create animation sequences of
objects morphing from one shape to the other.
How to do it...
The following code snippet shows how to create a morphing animated sequence between
three shapes. You can get the full code listing from ch03/source-code/src/animation/
ShapeMorphDemo.fx :
 
Search WWH ::




Custom Search