Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 23 ■ Completing the gameplay Code and player proofing your event handling


Next, let’s create an exact opposite of your moveCameraIn TranslateTransition Animation object by
copying and pasting this Animation object code underneath the rotCameraBack object. Everything should
be identical, except change the object name from moveCameraIn to moveCameraOut and reverse the -175
value in your .setByZ() method call. Your Java code to accomplish this is shown here, as well as highlighted
in yellow and blue in Figure 23-26:


moveCameraOut = new TranslateTransition(Duration.seconds(2), camera);
moveCameraOut.setByZ( 175 );
moveCameraOut.setCycleCount(1);


We can use your existing moveSpinnerOn Animation object that we used as one of the components
for the spinnerAnim ParallelTransition to move the spinner back onto the screen as the ParallelTransition
brings the camera back to its original game board spin position and orientation. This will demonstrate
that this Animation object can be used in more than one ParallelTransition object, which is a coding
optimization, as coding constructs can be used for more than one purpose. You can see this already coded
animation highlighted in yellow at the top of Figure 23-27.


Figure 23-26. Create a moveCameraOut TranslateTransition Animation object and change the .setByZ()
value to 175

Free download pdf