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 6 ■ The Foundation of Game Design: The <strong>Java</strong>FX Scene Graph and the InvinciBagel Game Infrastructure<br />

Game Design Foundation: Primary Function Screens<br />

One of the first things you want to design is the top-level, or highest-level, UIs that your game’s users will interface<br />

with. These will all be accessed using the InvinciBagel splash (branding) screen, contained in the primary<br />

InvinciBagel.java class code. As discussed previously, this <strong>Java</strong> code will extend the javafx.application.Application<br />

class and will launch the application, displaying its splash screen, along with options to review instructions, play the<br />

game, see the high scores, or review the game’s legal disclaimers and game creator credits (programmer, artist, writer,<br />

composer, sound designer, and so on). A high-level diagram showing the game, starting with functional UI screens at<br />

the top and progressing down to the OS level, can be seen in Figure 6-1.<br />

Figure 6-1. Primary game functional screens and how they are implemented through <strong>Java</strong> and <strong>Java</strong>FX API, using a JVM<br />

This will require adding three more Button nodes to your StackPane layout container Parent node as well as<br />

an ImageView node for the splash screen background image container. The ImageView node will have to be added<br />

to the StackPane first to be the first child node in the StackPane (z-order = 0), as this ImageView holds what I call<br />

the background plate for the splash screen UI design. Because it is in the background, the image would need to be<br />

behind the Button UI control elements, which will have z-order values of 1 through 4.<br />

This means that you will be using six Node objects (one parent node and five child nodes) in your application’s<br />

scene graph just to create your InvinciBagel splash screen! The instructions and credit screens will use another<br />

ImageView node, so you are up to six nodes already, and the high scores screen will likely use another two<br />

(ImageView and TableView) nodes, so you likely have more than eight nodes in the Scene Graph for creating the game<br />

support infrastructure before you have even considered adding the nodes for the game play screen, which is,<br />

of course, where you want to get the best performance possible for your game.<br />

This really is not so bad if you think about it, as these screens are all static and do not need to be updated, that<br />

is, the (UI) elements they contain are fixed and do not require updates using the pulse system, and so you should<br />

essentially still have 99 percent of the power of the <strong>Java</strong>FX pulse engine left over to process an InvinciBagel game<br />

GamePlayLoop engine. In fact, as <strong>Java</strong> 8 and <strong>Java</strong>FX 8 continue to improve the efficiency of their platform APIs and<br />

classes, you may actually have even more processing power left over for game play (sprite movements, collisions,<br />

physics, animation, and so on) and thus will be in good shape.<br />

The GamePlayLoop will process the game code for you, using the javafx.animation package and its<br />

AnimationTimer class. You will always need to be cognizant of how many Scene Graph Node objects you are asking<br />

the pulse engine to process, because, if this number gets to be too large, it will start to affect the game’s performance.<br />

124<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!