28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7<br />

The Foundation of Game Play Loop:<br />

The <strong>Java</strong>FX Pulse System and the<br />

Game Processing Architecture<br />

Now that you have created the top-level UI screens needed for your user to learn how to play the game, start the game,<br />

view high scores, and review the legal disclaimers and Ira H. Harrison Rubin’s InvinciBagel intellectual property game<br />

production credits, let’s get down to business and create the game play timing loop for your InvinciBagel game. This<br />

is of the greatest importance from a user experience standpoint, and is also critical to the proper functioning of the<br />

different game engines that you will be creating over the course of the remainder of this book, including the sprite<br />

engine, collision detection engine, animation engine, scoring engine, and physics engine. You will always keep<br />

smoothness of game play in mind; the efficient, optimal implementation of the <strong>Java</strong>FX pulse system is of paramount<br />

importance at this stage of the game (no pun intended). For this reason, I will be going into great detail in this chapter<br />

regarding the javafx.animation package, and how all of its functional classes differ from each other.<br />

First, you will explore the two Animation superclasses in the javafx.animation package: Animation and<br />

AnimationTimer. After that, you will take a look at Animation, Timeline, and Transition and how these classes, and<br />

any of their subclasses, such as PathAnimation and TranslateAnimation, will allow you to access the <strong>Java</strong>FX pulse<br />

event timing system. Now, you need to use pulse, if you want to create an action-oriented arcade type <strong>Java</strong> 8 game!<br />

You will also be taking a closer look at the overall structure of the entire javafx.animation package, because<br />

you’ll need to use one of these classes for your <strong>Java</strong> 8 game play loop. You will do this by using a diagram of the entire<br />

package, so that you can get an overview of how all its classes interrelate. You will then examine the class hierarchies<br />

among all of the <strong>Java</strong>FX Animation classes, in detail. With the exception of AnimationTimer, Interpolator,<br />

KeyFrame, and KeyValue, all of these javafx.animation package classes are subclassed (using the <strong>Java</strong> extends<br />

keyword) using the <strong>Java</strong>FX Animation superclass.<br />

Finally, you will be adding the new GamePlayLoop.java class into your invincibagel package, which will be<br />

created as a GamePlayLoop object in the InvinciBagel.java Application subclass, implementing the timing loop. This<br />

GamePlayLoop class will contain a .handle() method, as well as a .start() method and a .stop() method, which will<br />

allow you to control your GamePlayLoop timing events when the GamePlayLoop is operational, and to determine<br />

when it is latent (stopped or paused).<br />

I will create a diagram that will show the class and object hierarchy for this InvinciBagel game, so that you can<br />

start to visualize how these classes that you are coding, and objects that you are creating, will all fit together. It is<br />

almost as if the coding of a game using <strong>Java</strong> 8 and <strong>Java</strong>FX is in itself a (puzzle) game! Pretty cool stuff.<br />

www.it-ebooks.info<br />

145

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

Saved successfully!

Ooh no, something went wrong!