Game Development Reference
In-Depth Information
Next, let's test your ActionEvent handling, and later, the KeyEvent handling, by
clicking on the PLAY GAME Button control object. This should hide the
splashScreenBackplate and splashScreenTextArea ImageView objects, and reveal the
white background color which is set for the Scene object named scene using the Col-
or.WHITE constant.
As you can see, on the left half of Figure 11-16 , this is indeed the case, and our In-
vinciBagel character is on the screen, and we are ready to test the KeyEvent handling
that we put into place in Chapter 9 , and see if we can get the InvinciBagel (iBagel Ba-
gel object) character to move around on the screen. This is starting to get more and
more exciting with each successive chapter that we finish!
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
Let's test the worst case scenario first, and see how powerful the JavaFX pulse
event and key event handling infrastructure really is. Press the up key and the left ar-
row key, or the A key and the W key, at the same time . As you can see, the InvinciBa-
gel character moves smoothly and steadily on a diagonal vector, up and to the left. The
result of 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.
As you play around with your now motion-enabled InvinciBagel sprite, notice that
you are able to move him behind the UI buttons at the bottom of the screen, as seen on
the left half of Figure 11-17 . This happens because you have your .addGameActor-
Nodes() method called before your .addNodesToStackPane() method is called, which
gives everything in your game a lower Z-index than everything in your user interface
design. Also notice that you can move the InvinciBagel off of the screen (out of view
of the player), which we are going to address in Chapter 12 , when you will add to the
existing code to establish boundaries and implement other advanced movement fea-
tures. Finally, note that if you use the left and right arrow keys (not the ASDW keys),
 
 
 
Search WWH ::




Custom Search