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 15 ■ Implementing Game Audio Assets: Using the <strong>Java</strong>FX AudioClip Class Audio Sequencing Engine<br />

Figure 15-16. Use the Generate Setters dialog and create six .setiSound() methods<br />

Now we are ready to use these six new .setiSound() methods that NetBeans has coded for us, which we do not<br />

need, as our AudioClips are permanently “set” in memory using the .loadAudioAssets() method, to create the six<br />

.playiSound() methods that we do in fact need to play back these six digital audio assets. Let’s do that next.<br />

Providing Access to Your AudioClip: The .playiSound( ) Methods<br />

What we are about to do is what I consider another programmer’s shortcut, but instead of copy and paste, I used<br />

NetBeans Source ➤ Insert Code function to create Setter methods for the iSound objects that I am going to change<br />

from .setiSound() to .playiSound() methods, so that I do not have to type out all six of these method bodies. As you<br />

can see in Figure 15-17, NetBeans created six complete method bodies for us, and all that we have to do is to remove<br />

the AudioClip iSound references inside of the method parameter areas, change the setiSound() to be playiSound(),<br />

and finally change the this.iSound0 = iSound0; statement to be this.iSound0.play(); instead. We will do this for<br />

each of the six .setiSound() method bodies, which will allow us to quickly create six .playiSound() method bodies.<br />

Figure 15-17. Edit these six .setiSound() methods, created by NetBeans, at the bottom of the InvinciBagel.java class<br />

338<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!