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

Figure 15-20. Add conditional if() statements to the .playAudioClip() method that call the correct .playiSound()<br />

method<br />

Now we have added digital audio to our game engine infrastructure, and all we have to do later is swap out the<br />

voiceovers with sound effects, and we will have the digital audio portion of our game development completed. If you<br />

use a Run ➤ Project work process and test the code, you will find that audio samples trigger rapidly using <strong>Java</strong>FX.<br />

Summary<br />

In this fifteenth chapter, we changed our focus from how our game looks to our eyes (visual) and addressed how it<br />

sounds to our ears (aural), and took a chapter to implement the code for the AudioClip class so that we can trigger<br />

digital audio sound effects.<br />

First we took a look at the <strong>Java</strong>FX AudioClip class. We learned why it is perfectly suited for use in our game<br />

development for audio, including short musical loops (using the INDEFINITE constant setting) or rapid sound effects.<br />

Next, we learned how to optimize digital audio assets using Audacity 2.0.6. We learned the work process for<br />

optimizing digital audio so that it takes only a dozen or so kilobytes of system memory, and how to optimize audio so<br />

well that we do not even have to apply compression, especially since audio compression codecs supported by <strong>Java</strong> 8<br />

are “lossy” codecs and can degrade the quality of the audio data once they are decompressed into system memory.<br />

Finally, we implemented AudioClip objects in our InvinciBagel.java class using a .loadAudioAssets() method,<br />

and then created six .playiSound() methods to allow external classes to access and play these digital audio assets.<br />

We also added a .playAudioClip() method in our Bagel.java class that triggered the audio samples based on which<br />

keys were being pressed. In the next chapter, we are going take a look at how to add collision detection to our<br />

game code.<br />

www.it-ebooks.info<br />

341

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

Saved successfully!

Ooh no, something went wrong!