Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 21 ■ Questions and answers: Finishing the setup Methods and digital audio


Next, let’s take a break and implement the appearance of this StackPane and the Buttons in your
current code.


Implementing the New Q&A User Interface in Your JavaFXGame


The first thing that we’ll need to do in the Start Game Button gameButton.setOnAction() event handling
infrastructure is to hide the Q&A UI panel on game startup. After that, we will need to show this Q&A UI
panel once the camera has zoomed into the game board quadrant, which will require the addition of a
setOnFinished() method call to the end of the createAnimationAssets() method body. To hide the qaLayout
Q&A panel StackPane when the Start Game button is clicked, simply copy the first Java statement in the
handle() event handler inside of the gameButton.setOnAction() infrastructure and paste it underneath itself;
then change uiLayout to qaLayout, as shown here and as highlighted in Figure 21-15:


gameButton.setOnAction(new EventHandler() { // Using non-Lambda Expression
Format
@Override
public void handle(ActionEvent event) {
uiLayout.setVisible(false);
qaLayout.setVisible(false);
camera.setTranslateZ(500);
camera.setTranslateY(-300);
camera.setTranslateX(-260);
camera.setRotationAxis(Rotate.X_AXIS);
camera.setRotate(-30);
spinnerAnim.play();
}
});


Figure 21-14. Use your Run ➤ Project work process and make sure that the text on the buttons is readable

Free download pdf