Java Reference
In-Depth Information
F The hit —the Timeline instance assigned to variable ballAnim contains a keyframe
that gets executed over a period of 200 milliseconds (see previous bullets). At the
end of the period, when the ball is at the top of the screen, the keyframe executes
the function attached to its action property. That function:
Detects when the ball hits the paddle with the expression
Updates the score, increasing it by 1
Plays the socreAnim animation sequence to display the score (see
the previous score discussion)
There's more...
Building complex animations with several keyframes can get long and messy. To help with
the syntax burden, JavaFX supports a shortcut notation of the KeyFrame declaration using
the at() syntax. So the previous code snippet becomes:
def scoreAnim = Timeline {
keyFrames: [
at (1s) {
score.scaleX => 3;
score.scaleY => 3;
score.opacity => 0.0;
score.visible => false
The at() syntax provides a simpler way of expressing keyframes on the timeline. Each at()
is eventually mapped to a KeyFrame declaration and placed on the timeline.
The JavaFX KeyFrame animation API uses interpolation between keyframes to determine how
to fill in the missing animated frames in between the keyframes. Each key value can receive an
Interpolator type specified after the tween keyword (see code snippet). The interpolator in
JavaFX provides the algorithm that figures out how to fill in the missing frames while maintaining
synchronization with the timeline. There are several types of built-in interpolators with which you
should be familiar:
F Interpolator.EASEIN —starts the sequence slow and accelerates it smoothly to
a constant progression
F Interpolator.EASEOUT —decelerates the sequence from a constant progression,
with smooth deceleration, and an eventual stop
F Interpolator.EASEBOTH —uses both EASEIN and EASEOUT
Search WWH ::

Custom Search