Pro Java 9 Games Development Leveraging the JavaFX APIs

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

It’s also important to note that when you test your animation code, you need to click the Start Game
Button UI element as soon as the application launches (later, this will be triggered by a click on the 3D
spinner UI element, as you may have surmised already). This is so that you can see your animation
characteristics, which we are developing during this chapter, because currently your Java 9 code starts
the play life cycle immediately after the Animation (Transition subclass) object has been constructed and
configured. So, click your Start Game 2D UI button as soon as it appears!
Later, when we get into how to trap mouse clicks (or screen touches) on 3D objects, such as your
spinner UI element, we’ll trigger rotGameBoard.play() with a click on the spinner UI element to randomly
spin the gameboard to pick a new quadrant. We will trigger the rotSpinner.play() when the next player’s turn
is ready so they can spin the gameboard. We will be developing the complexity of this animation code during
the remainder of this book.
Later during this chapter, we will use TranslateTransition with RotateTransition using a
ParallelTransition, which will allow us to animate the 3D spinner UI element in and out of view so that the
player will know when to use it to randomly spin the game board to select a new quadrant (a new content
topic animal-vegetable-mineral or landmark category) for use in the gameplay cycle.
Next, let’s add the rotSpinner RotateTransition object. First turn your RotateTransition declaration
into a compound statement by adding the rotSpinner object name after the rotGameBoard object name at
the top of the class. Cut and paste the rotGameBoard statements after themselves, change rotGameBoard to
rotSpinner, and make sure to change the Node parameter of the instantiation from gameBoard to spinner.
Change fromAngle to 30 degrees (the starting value you developed in Chapter 15 ) and toAngle to 1110
degrees (1080 + 30). Your Java 9 code should look like the following method body, which is also highlighted
at the bottom of Figure 16-6:


Figure 16-5. Use your Run ➤ Project work process, click Start Game, and watch your gameboard spin around
smoothly

Free download pdf