28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7 ■ The Foundation of Game Play Loop: The <strong>Java</strong>FX Pulse System and the Game Processing Architecture<br />

Next, let’s study the threads analysis pane by scrolling down in the Profiler tab, shown at the top left of Figure 7-11.<br />

Find the Threads iconNetBeans will ask you if you want to start the threads analysis tool; once you agree, it will open<br />

the Threads tab (see Figure 7-12).<br />

Figure 7-12. Click the Threads icon, seen at the left of the screen, and open the Threads tab; the same eleven threads<br />

are running<br />

In case you are wondering why you are not seeing any “blips” in the Thread objects shown in Figure 7-12, like you<br />

did when you clicked the Button objects in the previous chapter, you are correct in your assumption that you should<br />

see the <strong>Java</strong>FX pulse engine timing events somewhere in this diagram Yet, all the thread bars are solid colored, so no<br />

action or pulse events are firing. I am going to have you use the NetBeans profiling utility as often as necessary to get<br />

you used to it, as many developers avoid this tool because they have not become comfortable with it.<br />

This reason you do not see any events is that simply creating the GamePlayLoop object is not enough for the<br />

.handle() method inside it to grab hold of pulse events. Because it is a Timer object of sorts (an AnimationTimer, to be<br />

exact), like any timer, it needs to be started and stopped. Let’s create these methods for the GamePlayLoop next.<br />

Controlling Your GamePlayLoop: .start( ) and .stop( )<br />

Because the AnimationTimer superclass has the .start() and .stop() methods, which control when the class (object)<br />

will (using a .start() method call) and will not (using a .stop() method call) handle pulse events, you will simply pass<br />

these functions “up” to the AnimationTimer superclass, using the <strong>Java</strong> super keyword inside your method code. You<br />

will override the .start() method by using the <strong>Java</strong> @Override keyword and then pass the method call functionality up<br />

to the AnimationTimer superclass by using the following method programming structure:<br />

@Override<br />

public void start() {<br />

super.start();<br />

}<br />

154<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!