Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

© Wallace Jackson 2017 239
W. Jackson, Pro Java 9 Games Development, https://doi.org/10.1007/978-1-4842-0973-8_10


CHAPTER 10


User Interface Design Interactivity:


Event Handling and Imaging


Effects


Now that you have finished the Scene Graph hierarchy for the splash screen and user interface design, let’s
get back into our JavaFXGame primary application class coding here in Chapter 10 and finish implementing
the event handling framework that you have in place but that is essentially “empty” (except for a few System.
out.println calls to test your Button Control Node objects). The Java and JavaFX event handling that we will
take an overview of during this chapter will implement the user interface that the player will use to learn
about and start your Java 9 game. During the book you will use other types of event handling (keystroke
and mouse) that we will look at during this chapter. You will be adding Java game UI programming logic
that could be looked at as an interactivity engine for your game. There are many ways to interface with
a game, including arrow keys, known as the DPAD (direction pad) for consumer electronics devices and
modern remote controls; a keyboard; a mouse; a trackball; a game controller; a touchscreen; or even
advanced hardware, including gyroscopes and accelerometers. One of the important choices that you will
make for your pro Java 9 game development will be how your players will interface with your Java game
using hardware devices that they are playing your game on and the hardware input capabilities the game
supports.
During this chapter you will be learning about the different types of JavaFX event types that are
contained in the javafx.event, javafx.scene.input, and the java.util packages. You will cover ActionEvent
since you are using this in your user interface design currently, as well as Input Events such as MouseEvent
and KeyEvent.
Besides continuing to work on your JavaFXGame Java code by adding event handling, you’ll be learning
about JavaFX Special Effects during this chapter, just to make sure I cover everything that is cool in Java
during this book. These JavaFX special effects are stored in the javafx.scene.effect package and give JavaFX,
and thus Java, a lot of the same special effects advantages that a digital image compositing software package
such as GIMP gives you.


Event Handling: Adding Interactivity to Your Games


One could argue that event handing is the foundation of game development. This is because if you don’t
have a way to interface with gameplay logic and game elements, you really don’t have much of a game. I’m
going to cover JavaFX event handling classes during this section of the chapter, and you will implement
your ActionEvent handing structures so that your users can utilize your user interface that you have been
designing over the past several chapters. The first thing I want to talk about before we start dissecting

Free download pdf