Game Development Reference
In-Depth Information
do this by installing a Color.WHITE background color in the Scene() constructor
method call (along with our new width and height variables), and then installing Java
code into our Button control event handler structure that are already in place, to hide
the two ImageView “plates” we are using for image compositing of our splash screen
UI design. We can also use these two ImageView Node objects later on to hold back-
ground imagery for our game play, once we get into that level of design. Remember it
is important to keep the number of Nodes in the Scene Graph to a minimum, so we will
reuse Node objects, instead of adding more.
The third upgrade we'll add is to add keyboard event handling routines to our
Scene object that will handle the arrow key support that we will use for the game, to
span any hardware device that has an arrow key pad or DPAD. This will handle any
events at the top-level of the Scene down to the StackPane (Scene Graph) hierarchy.
This will pass the arrow key values pressed by the user to our Node objects. This will
eventually allow motion control code to move the actors around the game, which is
something we will be getting involved with in greater detail in the next chapter.
Besides upgrading our InvinciBagel.java code, and adding keyboard event hand-
ling, we will also be learning about lambda expressions during this chapter, just to
make sure I get everything that is new in Java 8 covered during this topic. These
lambda expressions are somewhat advanced to be covered in this beginner level book,
but since they are a major new feature of Java 8, and provide multi-threading support
as well as more compact code structures, I am going to cover them here in this chapter,
partly because NetBeans 8 (no surprise here) is willing to code them for you!
Game Surface Design: Adding Resolu-
tion Flexibility
The first thing that I want to do to the InvinciBagel.java code, which should already be
open in a tab in NetBeans (if it is not, use the right-click and Open work process), is to
add WIDTH and HEIGHT constants for the game application. The reason for doing
this is that you may want to provide custom versions for netbooks or tablets (1024 by
600), or iTV set or eReaders (1280 by 720) or HDTV usage (1920 by 1080) or even for
new 4K iTV sets (4096 by 2160). Having a height and width variable allows you to not
have to change your Scene() constructor method call later, and to do certain screen
boundary calculations using these variables rather than “hard coded” numeric values
throughout your code. As you can see at the top of Figure 9-1 , I have created a con-
stant declaration for these two variables using a single line of Java code, which is
 
Search WWH ::




Custom Search