Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 4 ■ an IntroduCtIon to Game desIGn: Game desIGn ConCepts, Genres, enGInes, and teChnIques


High-Level Concepts: Static vs. Dynamic Gaming


I want to start with a high-level concept that touches everything that I will be talking about in this chapter,
from the types of games you can create to the optimization of games to the construction of your JavaFX
Scene Graph. We took a look at this concept in Chapters 2 and 3 , and we will look at it again in the next
chapter when we look at the concept of Java constants that are fixed or static and do not change versus Java
variables that are dynamic and change in real time. Similarly, user interface design in a JavaFX Scene Graph
can be static (fixed or immovable) or dynamic (animated, draggable, or skinnable) which means you can
change the UI look to suit your personal tastes.
The reason these concepts are so important in game design and development is because your game
engine, which you will design to “run” or “render” your game, will need to constantly check on (process)
the dynamic portions of your game to see if they have changed and therefore require a response. A response
requires processing, and Java code will need to be executed (processed) to update a score, move gameboard
positions, play animation frames, change a game piece’s state, calculate collision detection, calculate
physics, apply gameplay logic, and so forth. These dynamic checking requirements (and ensuing processing)
on every gameplay cycle (called the pulse in JavaFX) update to make sure that variables, positions, states,
animations, collisions, physics, and the like, are conforming to your Java game engine logic and can really
add up. This is why a balance of static versus dynamic in your game design is important; at some point, the
processor, which is doing all of this work, could get overloaded, slowing your gameplay down.
The result of this overloading of all the real-time, per-pulse checking that enhances the dynamics of
the gameplay is that the frame rate that your game is running at could decrease. That’s right, just like digital
video and animation, games have frame rates too, but game frame rates are based on the efficiency of your
programming logic. The lower the frame rate of the game, the less smooth the gameplay becomes, at least for
dynamic, real-time games such as arcade games. How smoothly a gameplays relates to how “seamless” the
user experience is for the customer.
For this reason, the concept of static versus dynamic is very important to every aspect of gameplay
design and makes certain types of games easier to achieve a great user experience for than other types. We
will be covering different types of games in a future section of this chapter, but as you might imagine, board
games are more “static” in nature, and arcade games are more “dynamic” in nature. That said, there are
game optimization approaches, which we’ll be covering during this book, that can make a game remain
dynamic (seem like lots is going on), when from your CPU’s processing point of view, what is really going on,
from a processing point of view, becomes manageable. This is one of the many tricks of game design, which,
when all is said and done, is about optimization in one way or another.
One of the most significant static versus dynamic design issues that I cover in Android (Java)
programming books is UI design using XML (static design) versus UI design using Java (dynamic design).
The Android platform will allow UI design to be done using XML instead of Java so that nonprogrammers
(designers) can do the front-end design for an application. JavaFX allows exactly the same thing to be done
by using JavaFX Markup Language (FXML).
You must create FXML JavaFX apps in order to do this, as you’ll see when you create your game
application in NetBeans 9 during Chapter 6. This option adds the javafx.fxml package and classes to
your application, allowing you to design UIs using FXML, and later have your Java programming logic
“inflate” them so that the design becomes JavaFX UI objects. It’s important to note that using FXML adds
another layer of processor overhead, including FXML markup and its translation (and processing), into the
application development and compilation process. For this reason and because, at the end of the day, this
is a Pro Java 9 Games Development book, not an FXML markup title, I am going to focus during this book on
how to do everything using Java 9 and the JavaFX APIs and not doing things by using FXML.
In any event, the point I am making regarding using XML (or FXML) to create the UI design is that this
XML approach could be viewed as “static,” because the design is created beforehand using XML and is
“inflated” at compile time using Java. The Java inflation methods use a designer-provided FXML design to
create a Scene Graph, which is filled with JavaFX UI objects, based on a UI design structure defined by using
FXML. A static UI is designed to be fixed to process a user interface for the game player and is placed into
memory one time when your game is loaded.

Free download pdf