Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 23 ■ Completing the gameplay Code and player proofing your event handling

The next thing that we need to create is the cameraAnimOut ParallelTransition Animation object
that will animate the camera object back out to your full game board (spin) view, as we will be calling the
.play() method off of that Animation object construct in the againButton.setOnAction() event processing
construct. Therefore, let’s create that ParallelTransition Animation object in the next section of this chapter,
as this will be a relatively complex task.


Camera Zoom Back Out: Another ParallelTransition


First let’s create an exact opposite of the rotCameraDown RotateTransition Animation object we created
earlier in the book by copying and pasting this Animation object code underneath the cameraAnimIn
object since we’re about to create the cameraAnimOut object. Everything will be identical, except change
the object name from rotCameraDown to rotCameraBack and exchange the values (-30 and -60) in the
.setFromAngle() and .setToAngle() method calls. The Java 9 code to accomplish this task is shown here, as
well as highlighted using yellow and blue in Figure 23-25:


rotCameraBack = new RotateTransition(Duration.seconds(5), camera);
rotCameraBack.setAxis(Rotate.X_AXIS);
rotCameraBack.setCycleCount(1);
rotCameraBack.setRate(0.75);
rotCameraBack.setDelay(Duration.ONE);
rotCameraBack.setInterpolator(Interpolator.LINEAR);
rotCameraBack.setFromAngle(-60);
rotCameraBack.setToAngle(-30);


Figure 23-25. Add the rotCameraBack RotateTransition object in createAnimationAssets() and instantiate
and configure it for use

Free download pdf