28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11 ■ Moving Your Action Figure in 2D: Controlling the X and Y Display Screen Coordinates<br />

Update Splashscreen Scene Graph: .createSplashScreenNodes()<br />

Now the time has come to reorganize our .createSplashScreenNodes() method body, and then we will be ready to get<br />

into “wiring up” the <strong>Java</strong>FX pulse engine that we created in our GamePlayLoop.java class to the Actor object that we<br />

created using our Actor.java, Hero.java and Bagel.java classes. We have already removed four lines of code from the<br />

end of the .createSplashScreenNodes() method, and placed them into the .loadImageAssets() method, where they<br />

more logically belong. The other thing that we need to do to try and streamline our .start() method is to group the<br />

ActionEvent handling structures with each of their respective object instantiations and configuration <strong>Java</strong> statements.<br />

Thus, your gameButton object instantiation, configuration, and event handling will all be kept together in one place,<br />

for instance. We will do the same thing for the helpButton, scoreButton, and legalButton objects. The event handling<br />

structures that I copied from the .start() method into the .createSplashScreenNodes() method are shown here in bold.<br />

The new .createSplashScreenNodes() method body will contain the following three dozen lines of <strong>Java</strong> code:<br />

private void createSplashScreenNodes() {<br />

buttonContainer = new HBox(12);<br />

buttonContainer.setAlignment(Pos.BOTTOM_LEFT);<br />

buttonContainerPadding = new Insets(0, 0, 10, 16);<br />

buttonContainer.setPadding(buttonContainerPadding);<br />

gameButton = new Button();<br />

gameButton.setText("PLAY GAME");<br />

gameButton.setOnAction((ActionEvent) -> {<br />

splashScreenBackplate.setVisible(false);<br />

splashScreenTextArea.setVisible(false);<br />

});<br />

helpButton = new Button();<br />

helpButton.setText("INSTRUCTIONS");<br />

helpButton.setOnAction((ActionEvent) -> {<br />

splashScreenBackplate.setVisible(true);<br />

splashScreenTextArea.setVisible(true);<br />

splashScreenTextArea.setImage(instructionLayer);<br />

});<br />

scoreButton = new Button();<br />

scoreButton.setText("HIGH SCORES");<br />

scoreButton.setOnAction((ActionEvent) -> {<br />

splashScreenBackplate.setVisible(true);<br />

splashScreenTextArea.setVisible(true);<br />

splashScreenTextArea.setImage(scoresLayer);<br />

});<br />

legalButton = new Button();<br />

legalButton.setText("LEGAL & CREDITS");<br />

legalButton.setOnAction((ActionEvent) -> {<br />

splashScreenBackplate.setVisible(true);<br />

splashScreenTextArea.setVisible(true);<br />

splashScreenTextArea.setImage(legalLayer);<br />

});<br />

buttonContainer.getChildren().addAll(gameButton, helpButton, scoreButton, legalButton);<br />

splashScreenBackplate = new ImageView();<br />

splashScreenBackplate.setImage(splashScreen);<br />

splashScreenTextArea = new ImageView();<br />

splashScreenTextArea.setImage(instructionLayer);<br />

}<br />

240<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!