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 11 ■ Moving Your Action Figure in 2D: Controlling the X and Y Display Screen Coordinates<br />

Yet again you have made a ton of progress during this chapter in getting your primary InvinciBagel.java class<br />

optimized, implementing all of the classes that you have coded thus far in this book, wired the game play loop engine<br />

into your primary game character, tested all of your ActionEvent and KeyEvent handling, and had an all-around good<br />

time doing it! I would call that a pretty successful chapter, and we will continue to have a good time in every chapter!<br />

Summary<br />

In this eleventh chapter, we reorganized our primary InvinciBagel.java class to extract the five key game creation<br />

<strong>Java</strong> statements, and then organized the rest of the <strong>Java</strong> code into eight logical methods (routines), six of them<br />

which we created from scratch during this chapter. The six new methods serve to parcelize things such as adding<br />

Image assets, creating new Actor objects, adding Actors to the Scene Graph, adding Actors to the Cast, creating and<br />

starting the Game Engine, and implementing the game key event handling routines. We added object declarations<br />

so that we could create a new iBagel Bagel object for our game’s primary character, and also created a castDirector<br />

CastingDirection engine so that we could manage our cast members as we add them to the game in later chapters.<br />

We learned about import static statements, and we saw how to use them to wire our iBagel Bagel object to the<br />

GamePlayLoop.java engine .handle() method. We also used these import static statements to allow our Bagel.java<br />

class to process the Boolean up, down, left, and right variables in the .update() method.<br />

Next, we covered how to use conditional if statements to determine which key events (held in four Boolean<br />

variables) were being used by the game player. We placed this logic inside of the Bagel class .update() method, which<br />

as we know is being rapidly executed 60 times per second by the GamePlayLoop .handle() <strong>Java</strong>FX pulse engine.<br />

Finally we tested all of the new methods and <strong>Java</strong> statements that we added during the chapter to see if the basic<br />

game sprite movement works. We observed some of the things that we will need to address in future chapters, and<br />

thoroughly tested the existing KeyEvent handling methods and iX, iY, vX, and vY attributes of the abstract Actor class<br />

that we created as the foundation for all of our game actor assets.<br />

In the next chapter, we are going to take a closer look at the <strong>Java</strong>FX Node class and also take a look at advanced<br />

concepts regarding moving the game sprite around your screen, as well as how to ascertain the boundary (edges) of<br />

the screen, character direction, movement velocity, and related animation and movement considerations.<br />

249

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

Saved successfully!

Ooh no, something went wrong!