Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 23 ■ Completing the gameplay Code and player proofing your event handling

The next thing we need to ascertain (and code) is when we allow Button UI elements to be clicked. This
logically would be at the end of the cameraAnimIn Animation object, again in the .setOnFinished() event
handler construct right after the qaLayout and scoreLayout StackPane 2D UI panels (and their contents
or children) have been set to be visible again by using the .setVisible(true) method call off of each of the
StackPane UI container objects. As buttonClick is false as a (declaration) default, this is as simple as using
the buttonClick = true; Java statement.
Once one of the answer Button UI objects has been clicked, buttonClick will again be set to false,
preventing any Button UI object (even the same one) from being clicked until a cameraAnimIn Animation
object is played again. We will put this Java code into place next in the createQAprocessing() scoring method
inside each of the ActionEvent handling structures attached to each of the four Button objects in their
.setOnAction() event-handling constructs.
Your new cameraAnimIn Java 9 code should now look like the following and can also be seen
highlighted in light blue and yellow at the bottom of Figure 23-14:


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


Now that the camera has animated in close to the game board surface and the buttonClick boolean
variable has been set to true to allow a click on the Button to select an answer, we need to tell the buttonClick
variable to turn itself off (false) when that one button (a1Button through a4Button) has been clicked.


Figure 23-14. Add a buttonClick = true; statement to the end of the cameraAnimIn.setOnFinished() event
handler code

Free download pdf