28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9 ■ Controlling Your Action Figure: Implementing <strong>Java</strong> Event Handlers and Using Lambda Expressions<br />

Finishing the UI Design: Coding a Game Play Button<br />

The next thing that we will need to do is to finish the Button control event handling code so that when we click on<br />

the GAME PLAY Button object, the white background is revealed for us to develop our game over. Later on we can<br />

use the ImageView plates that we use for our splash screen support to provide background image compositing<br />

for the game to make it more interesting visually. The way that we are going to hide the two ImageView Node<br />

objects in the Scene Graph is by calling the .setVisible() method off of each of these objects inside of the<br />

.handle() method that is attached to the PLAY GAME UI Button object. This can be seen in the bottom portion<br />

of Figure 9-2, and would be implemented using the following two lines of <strong>Java</strong> code, inside of the .handle()<br />

EventHandler method structure:<br />

splashScreenBackplate.setVisible(false);<br />

splashScreenTextArea.setVisible(false);<br />

Figure 9-2. Use a .setVisible() method for the ImageView class to hide background image plates and reveal White color<br />

As you can see, there is also a wavy yellow warning highlight under the EventHandler part of<br />

this event handling structure which relates to <strong>Java</strong> lambda expressions. After we finish implementing all of the<br />

final UI design code for the Buttons that controls what is visible to the player, and which imagery it is showing<br />

them, I will get into lambda expressions, and we will get rid of these warning messages in your code as well.<br />

After that, we’ll move on to implement arrow key event handling structures, so that the user can navigate the<br />

InvinciBagel around the screen.<br />

First, let’s test the code that we put into the previously empty PLAY GAME Button event handling structure.<br />

www.it-ebooks.info<br />

189

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!