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 />

Figure 11-16. Hold a left arrow (or A) and up arrow (or W) key down at the same time, and move the Actor diagonally<br />

Let’s test the worst case scenario first, and see how powerful the <strong>Java</strong>FX pulse event and key event handling<br />

infrastructure really is. Press the up key and the left arrow key, or the A key and the W key, at the same time. As you<br />

can see, the InvinciBagel character moves smoothly and steadily on a diagonal vector, up and to the left. The result of<br />

this can be seen on the right half of Figure 11-16. Try using the individual keys as well, to make sure they are working.<br />

As you play around with your now motion-enabled InvinciBagel sprite, notice that you are able to move him<br />

behind the UI buttons at the bottom of the screen, as seen on the left half of Figure 11-17. This happens because you<br />

have your .addGameActorNodes() method called before your .addNodesToStackPane() method is called, which gives<br />

everything in your game a lower Z-index than everything in your user interface design. Also notice that you can move<br />

the InvinciBagel off of the screen (out of view of the player), which we are going to address in Chapter 12, when you<br />

will add to the existing code to establish boundaries and implement other advanced movement features. Finally, note<br />

that if you use the left and right arrow keys (not the ASDW keys), the Button control focus (the blue outline) moves as<br />

well, which means that we will also have to fix this in a future chapter, by having our KeyEvents “consumed.” As you<br />

can see, there is lots of really cool code to write and things about <strong>Java</strong> 8 and <strong>Java</strong>FX 8.0 to learn before we’re finished!<br />

Figure 11-17. Notice the InvinciBagel character is using a lower Z-index than the UI elements, and can move off-screen<br />

248<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!