Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 23 ■ Completing the gameplay Code and player proofing your event handling


Finishing the Play Again Button: resetTextureMaps()


We are now going to expand the five lines of code inside the againButton.setOnAction() event handling
infrastructure so that we call the new camera Animation object and the existing AudioClip object to add
animation and digital audio to the part of the game that returns the player to the zoomed-out view, where
they can randomly spin the game board to select new content to test their knowledge base. We are also going
to move your resetTextureMaps() method call from inside the createSceneProcessing() method into this
game-reset event processing method so that the game board squares and quadrants are reset to blank when
gameplay is finished and right before the camera zooms back away from the game board (and before the
camera zoom audio effect is played to match that animation). We will also be hiding the againButton Button
UI element as part of this process, since we do not want that Button UI element to overlay the view of our i3D
spinner and game board spinning around to randomly select the next quadrant.
Add a .setVisible(false) method call off the againButton after your qaLayout and scoreLayout visibility
calls. Next, add a resetTextureMaps() call and .play() calls off cameraAnimOut and cameraAudio at the end
of the method.
The Java 9 code for the event handling should now look like the following and is also shown in
Figure 23-28:


againButton = new Button();
againButton.setText("Let's Play Again!);
againButton.setFont(Font.font( "Arial Black", 35 ) );
againButton.setBackground(new Background(new BackgroundFill(Color.Yellow,
CornerRadii.EMPTY, Insets.
Empty);
againButton.setMinSize(300, 200);
againButton.setTranslateX(190);
againButton.setTranslateY(-580);
againButton.setTranslateZ(100);
againButton.setOnAction( (ActionEvent event) -> {
qaLayout.setVisible(false);
scoreLayout.setVisible(false);
againButton.setVisible(false);
buttonClick = false;
squareClick = false;
spinnerClick = false;
resetTextureMaps();
cameraAnimOut.play();
cameraAudio.play();
}

Free download pdf