Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


Next, let’s take a look at the TranslationTransition, which can be used to move objects around the 3D
Scene in any of the X, Y, or Z dimensions. We will be using this to bring our spinner UI element onto (and off
of ) the screen as it is needed during gameplay to allow the player to randomly spin the game board to select
their new topic quadrant.


Animating Node Movement: Using the TranslateTransition Class


The public final TranslateTransition class extends the public abstract Transition superclass and is kept
in the javafx.animation package in the javafx.graphics module. A TranslateTransition creates a move
(translate) animation, which lasts as long as its duration property. Movement is created by updating
translateX, translateY, and translateZ variables (properties) of the Node you are animating at an interval
defined by the Interpolator constant. Translation will start from the “from” value (fromX, fromY, fromZ) if
one is provided; otherwise, the algorithm will use the Node object’s current position (translateX, translateY,
translateZ) value. Translation stops at the “to” value (toX, toY, toZ), if it is provided; otherwise, it will use the
start value, plus the byX, byY, or byZ value. The “to” value (toX, toY, toZ) will take precedence if both “to”
(toX, toY, toZ) and “by” (byX, byY, byZ) values have been specified.


java.lang.Object



javafx.animation.Animation
javafx.animation.Transition
javafx.animation.TranslateTransition



Figure 16-8. Adjust the rotSpinner.setToAngle() method call to spin in a negative direction so the spinner UI
spins forward

Free download pdf