How it works...
Using transition-based animation is a simple and easy way to get started quickly with building
animation sequences. Recall that a transition class provides a canned timeline that animates
specific attributes on a node, including position and dimension. This recipe makes use of the
ParallelTransition class. This is a special transition class used to compose animation
sequences by animating simpler transition sequences in parallel. Let's examine how the code
F Animated subject —in this recipe, there are two subjects being animated. The first one
is a Group instance named circles that is composed of two adjoining circles. The
other subject is a Rectangle ( rect ) instance.
F Animation setup —the animation is driven by an instance of ParallelTransition .
This is a specialized transition class used as a container for other transition sequences.
It provides a way to declaratively compose elaborate animation sequences by
assembling together simpler animation transitions running in parallel.
F Animation sequences —the ParallelTransition class is used to drive three transition
sequences on two objects:
circles —the group of circles rotate 360 degrees using the
RotateTransition for a period of one second. While the
circles rotate, they are also translated for three seconds from
the left-hand side to the right-hand side of the screen using the
rect —the other instance of TranslateTransition is used
to animate the rectangle on the stage from the top of the screen
toward the bottom for a period of three seconds.
F Animation playback —when the play() function is invoked on ParallelTransition ,
it starts the animation in parallel for each individual transition that it contains. Each
transition element applies control properties from their own timeline, honoring its
repeatCount and autoReverse properties respectively. This is to allow each
timeline to move independently and in parallel.
The JavaFX animation framework also offers a SequentialTransition class to
compose animation sequences that are played serially (as opposed to parallel). Similar
to the ParallelTransition class, the SequentialTransition class allows you to
compose animation using a collection of simpler transition classes. Unlike the parallel
animation sequence though, each sequence plays one after the other. The next snippet
shows how we can animate the same objects presented in the recipe earlier using the
SequentialTransition class. The full code can be found in ch03/source-code/src/