Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 16 ■ 3D Game animation Creation: UsinG the animation transition Classes


The .toXProperty() method call is used to specify a stop X coordinate value for a TranslateTransition object.
The .toYProperty() method call is used to specify a stop Y coordinate value for a TranslateTransition object. The
.toZProperty() method call is used to specify a stop Z coordinate value for a TranslateTransition object.
The .durationProperty() method call will return the current duration property for the
TranslateTransition. A .getDuration() method call is used to get the Duration value for the
TranslateTransition duration property. The void .setDuration(Duration value) can be used to set (specify)
the Duration value of the duration property.
The .nodeProperty() method call will return the target node Node property for the TranslateTransition.
The .getNode() method call will get (read) the Node object reference value for the node property
of a TranslateTransition. The void .setNode(Node value) method call will set the Node value for a
TranslateTransition node property. The void .interpolate(double frac) method call will always need to be
provided by subclasses of Transition.
Next, let’s implement a TranslateTransition Animation object that moves the spinner UI element
onto and off of the screen. These Animation objects will eventually be named moveSpinnerOn and
moveSpinnerOff. After that we will get into the ParallelTransition class and combine the movement and
rotation to spin the spinner UI element across the screen, from the left corner to the right corner.


TranslateTransition Example: Set Up Translate Animation Assets


Let’s add a TranslateTransition Animation object to your game project by declaring one named
moveSpinner at the top of the class and then instantiate it inside of the createAnimationAssets() method,
after the RotateTransition Java code. Reference the spinner Node and use a five-second duration. Next,
configure the moveSpinnerOn Animation object to move by 1150 X units across the top of the screen
(actually 1350 units, as the spinner is currently at -200) and set the cycleCount property to one cycle, using
the following Java statements, shown highlighted in yellow in Figure 16-9:


TranslateTransition moveSpinnerOn;
...
moveSpinnerOn = new TranslateTransition(Duration.seconds(5), spinner);
moveSpinnerOn.setByX( 1150 );
moveSpinnerOn.setCycleCount( 1 );

Free download pdf