Java Reference
In-Depth Information
This chapter is about pure, unadulterated eye candies. In previous chapters, you were
introduced to the fundamentals of the language and framework. Now, it's time to explore
the fun side of JavaFX. You will learn how to use transformation techniques to manipulate
the location and dimension of objects in the scene. You will learn how to use JavaFX's
Animation API to animate objects in order to create compelling content. Finally, you will
learn how to make your objects visually appealing by applying paint and effects to
your objects.
The JavaFX animation framework
Let's take a quick look into the animation framework before we move on. The built-in
animation framework allows developers to animate an object easily using JavaFX's declarative
syntax. You simply describe the state of the object at certain keyframes in the sequence, and
the animation engine fills in the rest of the frames.
JavaFX supports two types of animations including transition- and keyframe-based
animations. Transition-animations are prepackaged sequences that animate a given property
(dimension, opacity, location, and so on). Keyframe-animation provides total control over the
animation by exposing a complete idiom to express the animated sequence declaratively with
timelines and keyframes.
Lastly, JavaFX's Animation API makes use of the built-in Duration type to represent time
periods used in animation sequences (see Chapter 1 , Creating and Using Variables ). The
Duration type provides a literal that provides a natural representation of time by specifying
a number and a time unit together as shown in the next code snippet. For instance, the
following code snippet expresses two minutes (see full code at ch03/source-code/src/
DurationTest.fx ).
var twoMinutes = 0h + 1m + 30s + 30000ms ;
if(twoMinutes != 2m) println("Assertion failed");
if(twoMinutes != 120s) println("Assertion failed");
if(twoMinutes != 120000ms) println("Assertion failed");
Modifying shapes with the Transformation
There will be a time when you will want to modify the shape of your objects into something
completely different. You can tediously update positional or dimensional properties one
by one, or you can use the Transformation-API. This recipe shows you how to use the
Transformation API to transform a shape's physical properties declaratively and effortlessly.
Search WWH ::

Custom Search