Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 21 ■ Questions and answers: Finishing the setup Methods and digital audio

The next thing to do after hiding your Q&A UI Panel the first time (until it is needed) is to show it right
after the 3D camera has been rotated and moved into the game board once the player has selected the
game board square that they want to play. The theory here is that because of a new camera focal length
(unit repositioning) and camera angle (rotation to 60 degrees from 30 degrees), the new Q&A Panel visual
characteristics may have changed. In other words, different rendering parameters may have altered any of
(or all of ) the StackPane, Button, and even font characteristics.
In fact, not surprisingly, this did occur, so after we implement the new cameraAnimIn.setOnFinished()
event handler, we will need to go back into the createQAnodes() method body and “tweak” the Q&A UI
Panel parameters to more closely align it with the bottom-left corner of the “question answers selection”
gameplay view. We will also tighten up the spacing around the answer Button UI elements and increase the
font size while we are at it!
After the cameraAnimIn ParallelTransition object instantiation, add your setOnFinished() method call
off of the cameraAnimIn object and place a qaLayout.setVisible(true); statement inside the event handling
infrastructure so that your Q&A UI Panel can be seen after the camera zooms into the randomly selected game
board quadrant after the player clicks the game board square to which they think they will know the answer.
This new Java code construct is shown here, as well as highlighted in blue and yellow in Figure 21-16:


private void createAnimationAssets() {
...
cameraAnimIn = new ParallelTransition(moveCameraIn, rotCameraDown, moveSpinnerOff);
cameraAnimIn.setOnFinished(event->{
qaLayout.setVisible(true);
});
}


Figure 21-15. Hide the Q&A UI panel on the game startup by using qaLayout.setVisible(false) in the start()
method

Free download pdf