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

Like the AudioClip class, the URL class was also scratch coded to provide URL objects, as you can see from the<br />

<strong>Java</strong> class hierarchy, which looks like the following:<br />

java.lang.Object<br />

> java.net.URL<br />

The second step in our implementation of our six AudioClip objects is the declaration of six private URL objects<br />

named iAudioFile0 through iAudioFile5 at the top of the InvinciBagel.java class using a compound declaration<br />

statement, which can be seen in Figure 15-12, and looks like the following single line of <strong>Java</strong> code:<br />

private URL iAudioFile0, iAudioFile1, iAudioFile2, iAudioFile3, iAudioFile4, iAudioFile5;<br />

Figure 15-12. Add a private URL compound declaration statement for the iAudioFile0 through iAudioFile5 URL objects<br />

As you can see in Figure 15-12, you will have to again use the Alt-Enter work process, and select the “Add import<br />

for java.net.URL” option, and again have NetBeans 8 write your URL class import statement for you.<br />

Now we are ready to write the <strong>Java</strong> code that loads our URL objects, and then uses these to instantiate our<br />

AudioClip objects. To maintain our high level of code organization using custom methods inside this class, let’s add a<br />

loadAudioAssets() method into our .start() method next, and then create a private void loadAudioAssets() method to<br />

hold our AudioClip related code, in case we want to add more than six digital audio assets into our game in the future.<br />

It is important to note that due to the versatility of the AudioClip class as far as pitch shifting and 2D spatial (left<br />

to right) audio movement is concerned, you should not need as many audio assets as you might think, because you<br />

can turn even six well-designed audio assets into literally hundreds of different sound effects for your game play.<br />

334<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!