Pro Java 9 Games Development Leveraging the JavaFX APIs

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

Finally, to make this a compound animation, we’ll add a cameraAnimIn ParallelTransition object
declaration, making a compound declaration at the top of your class, and then we’ll instantiate the object
inside createAnimationAssets().
We will add the moveCameraIn and rotCameraDown animation objects to this ParallelTransition
object, right inside the object instantiation statement, so we will need only one line of code to combine these
two animations together seamlessly. The Java code, also shown at the end of Figure 20-22, should look like
the following:


cameraAnimIn = new ParallelTransition(moveCameraIn, rotCameraDown);


Next, let’s use a Run ➤ Project work process and test this code to see how it works! As you can see
in Figure 20-21, the quadrant is in a good location on the screen, so all we have to do is to move the 3D
spinner UI off of the screen. To accomplish this, we will add a moveSpinnerOff animation object to the
cameraAnimIn ParallelTransition so that part of rotating the camera into the game board also involves
moving the 3D spinner off of the gameplay screen.


This will make the animation sequence look much more professional. We can use your original
spinnerAnim ParallelTransition object to get the 3D spinner UI onto the screen whenever we need to spin
your game board again.
Let’s create the moveSpinnerOff animation object next, and then we can add it to the cameraAnimIn
object that we just created to create a more complex ParallelTransition Animation object to use in your
gameplay code.
Declare a moveSpinnerOff object in your compound TranslateTransition declaration statement
at the top of the class and then instantiate it in your createAnimationAssets() method body, after your
moveCameraIn statements and before the cameraAnimIn ParallelTransition object instantiation, since we
are going to add it to this compound animation transition. This way, everything that we want to animate
happens at exactly the same time.


Figure 20-21. The camera now points down 60 degrees at the game board displaying the content better

Free download pdf