Java Reference
In-Depth Information
F KeyFrame —this class represents a keyframe in the animation sequence with the
following properties:
time:Duration —the time period used for the extrapolation of
in-between frames for the animation sequence.
values:KeyValue[] —a collection of KeyValue classes that
are used to express the initial and the terminal values of the key
values for the animation sequence. That expression takes the form
initial_value => terminal_value , specifying the key values
that are interpolated by the animation engine over the specified
time period.
action:function() —is a function which can be attached to the
keyframe. It is invoked when the keyframe's duration has elapsed.
Let's see how the recipe makes use of the keyframe animation constructs. The code uses
three distinct timeline instances to animate the objects for the game. Let's also see how
they are used:
F The score —the first animation sequence displays the game's score. This is
accomplished through the scoreAnim Timeline instance. It is used to interpolate
properties scaleX => 3 , scaleY => 3 , opacity => 0 , and visible =>
false of the text node score text node score over a period of one second. When
the animation is executed, the current score is animated showing the text for the
score zooming in while fading simultaneously.
F The paddle —the paddle (an instance of Rectangle assigned to variable paddle )
runs left and right on the top of the screen. It is animated by an instance of Timeline
assigned to variable paddleAnim . The timeline has a single KeyFrame object that
interpolates the translateX property of the paddle object to move it across the
screen. The call to runs the paddle's animation indefinitely
because repeatCount=INDEFINITE , and the paddle goes back and forth because
autoReverse=true .
F The ball —when the ball (an instance of Circle assigned to the variable ball ) is
clicked on, it travels from the bottom of the screen, moving upwards toward the
paddle's trajectory. The ball is animated using variable binding where the ball.
centerY property is bound to the variable cy. A Timeline instance , assigned
to variable ballAnim , updates cy with two keyframes: at 200 ms variable cy is set
to five (corresponding to the top of the screen); at 500 ms , cy is assigned an
expression (h - rad) corresponding to the bottom of the screen. As ballAnim
interpolates cy , ball.centerY is updated, thus animating the circle. To start
the animation, ball includes an onMousePressed event handler used to call
ballAnim.playFromStart() .
Search WWH ::

Custom Search