[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 5 ■ An Introduction to Game Design: Concepts, Multimedia, and Using Scene Builder<br />
High-Level Concept: Static vs. Dynamic<br />
I want to start out with a high-level concept that touches on everything that I will be talking about in this chapter, from<br />
the types of games you can create, to game optimization, to <strong>Java</strong>FX Scene Builder and <strong>Java</strong>FX Scene Graph. You took<br />
a look at this concept back in Chapter 3, whether you realized it or not, while exploring the concept of a <strong>Java</strong> constant,<br />
which is fixed, or static, and does not change, versus a <strong>Java</strong> variable, which is dynamic and changes in real time.<br />
Similarly, a UI design in <strong>Java</strong>FX Scene Graph can be static (fixed and immovable) or dynamic (animated, draggable, or<br />
skinnable, meaning that you can change the UI look to suit your personal taste).<br />
The reason these concepts are important in game design and development is that your game’s engine, which you<br />
design to run or render your game, must constantly check on its dynamic portions to see if they have changed and<br />
require a response (update a score, move a sprite position, play an animation frame, change the game piece’s state,<br />
calculate collision detection, calculate physics, and so on). This checking (and the ensuing processing) on every frame<br />
update (called a pulse in <strong>Java</strong>FX; see Chapter 4), to make sure that all your variables, positions, states, animations,<br />
collisions, physics, and the like are conforming to your <strong>Java</strong> game engine logic, can really add up, and, at some point,<br />
the processor that is doing all this work can get overloaded, which can slow it down!<br />
The result of this overloading of all the real-time, per-frame checking that enhances the dynamics of your game<br />
(play) is that the frame rate at which your game is running will decrease. That’s right, like digital video and animation,<br />
<strong>Java</strong> 8 games have frame rates, too, but <strong>Java</strong> 8 game frame rates are based upon the efficiency of your programming<br />
logic. The lower the frame rate of your game, the less smooth the game play becomes, at least for dynamic, real-time<br />
games, such as arcade games; how smoothly a game plays relates to how seamless (enjoyable) the user experience is<br />
for the customer, the game player.<br />
For this reason, the concept of static versus dynamic is very important to every aspect of game play design and<br />
makes it easier to achieve a great user experience with certain types of games than with others. I will be discussing<br />
different types of games later in the chapter (see the section “Types of <strong>Games</strong>: Puzzles, Board <strong>Games</strong>, Arcade <strong>Games</strong>,<br />
Hybrids”), but, as you might imagine, board games are more static in nature, and arcade games are more dynamic.<br />
That said, there are optimization approaches that can keep a game dynamic, that is, seem like a lot is going on, when,<br />
from a processing point of view, what is really going on is quite manageable. This is one of the many tricks of game<br />
design, which, when all is said and done, is about optimization.<br />
One of the most significant static-versus-dynamic design issues in Android (<strong>Java</strong>) programming is UI design<br />
using XML (static design) versus UI design using <strong>Java</strong> (dynamic design). The Android platform allows UI design to be<br />
done using XML instead of <strong>Java</strong> so that nonprogrammers (designers) can do the front-end design for an application.<br />
<strong>Java</strong>FX allows exactly the same thing to be done using FXML. You have to create an FXML <strong>Java</strong>FX application to do<br />
this, as you saw in Chapter 2 (see Figure 2-4, right-hand side, third option, “<strong>Java</strong>FX FXML Application”). Doing so will<br />
add the javafx.fxml package and classes to the application, letting you design UIs, using FXML, and later having your<br />
<strong>Java</strong> programming logic “inflate” them so that the design consists of <strong>Java</strong>FX UI objects.<br />
It is important to note that using FXML adds another layer, containing the FXML markup and its translation and<br />
processing, to the application development and compilation process. I am going to demonstrate later in the chapter<br />
how this is done, in case your design team wants to use FXML for the UI design work process, instead of <strong>Java</strong> (see the<br />
section “<strong>Java</strong>FX Scene Builder: Using FXML for UI Design”). I am doing this because I want to cover all the design<br />
options in <strong>Java</strong>FX, including FXML, to make sure that this book is complete in its coverage of what can be done using<br />
<strong>Java</strong> 8 and <strong>Java</strong>FX 8.0. At the end of the day, this is a <strong>Java</strong> 8 programming title, however, so my primary focus during<br />
this book will be using <strong>Java</strong> 8, not FXML.<br />
In any event, the point that I am making regarding using XML (or FXML) to create the UI design is that this<br />
approach can be viewed as static, because the design is created beforehand, using XML, and is “inflated” at compile<br />
time, using <strong>Java</strong>. <strong>Java</strong> inflation methods use the designer-provided FXML structure to create the scene graph, which<br />
is filled with <strong>Java</strong>FX UI (class) objects, based on the UI design structure (hierarchy) created using FXML. I will give<br />
you an overview of how this works later in the chapter so that you have a handle on how this works (see the section<br />
“<strong>Java</strong>FX Scene Builder: Using FXML for UI Design”).<br />
102<br />
www.it-ebooks.info