Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 20 ■ Coding gameplay: Set Up gameplay methodS and animated Camera View

The Java 9 code for this camera object calling a RotateTransition object, shown in Figure 20-20,
should look like the following:


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


Since we also want to move the camera object in by -175 units, from 500 to 325, at the same
time we are rotating the camera object down -30 degrees, we will add a moveCameraIn object to the
TranslateTransition object compound declaration statement at the top of your class. At the end of the
createAnimationAssets() method, we will instantiate this object using 2 seconds and attach it to the
camera object. Then we will configure it to move by -175 units in the Z direction by using setByZ(-175), with
a cycleCount setting of 1. The Java code for this animation object should look like the following:


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


Figure 20-20. Add a rotCameraDown animation at the end of the createAnimationAssets() method from
-30 to -60

Free download pdf