Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 16 ■ 3D Game animation Creation: UsinG the animation transition Classes

Use the Run ➤ Project work process to see both gameBoard and spinner rotating, as shown in
Figure 16-7.


As you can see, the only problem is that your “SPIN” spinner is rotating backward, and we want the
word SPIN to rotate forward, so we’ll need to change the direction by setting fromAngle to 30 and toAngle
to -1050 (1080 = 30 - -1050). The final Java code block is shown here, as well as highlighted in yellow and
blue in Figure 16-8:


RotateTransition rotGameBoard, rotSpinner;
...
private void createAnimationAssets() {
rotGameBoard = new RotateTransition(Duration.seconds(5), gameBoard);
rotGameBoard.setAxis(Rotate.Y_AXIS);
rotGameBoard.setCycleCount(1);
rotGameBoard.setRate(0.5);
rotGameBoard.setInterpolator(Interpolator.LINEAR);
rotGameBoard.setFromAngle(45);
rotGameBoard.setToAngle(1125);
rotGameBoard.play();
rotSpinner = new RotateTransition(Duration.seconds(5), spinner);
rotSpinner.setAxis(Rotate.Y_AXIS);
rotSpinner.setCycleCount(1);
rotSpinner.setRate(0.5);
rotSpinner.setInterpolator(Interpolator.LINEAR);
rotSpinner.setFromAngle( 30 );
rotSpinner.setToAngle(-1050); // Reverse rotation direction using a negative toAngle
value
rotSpinner.play();
}


Figure 16-7. Select Run ➤ Project and click Start Game to preview the game board and spinner rotation

Free download pdf