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

Implementing Game Audio Assets:<br />

Using the <strong>Java</strong>FX AudioClip Class<br />

Audio Sequencing Engine<br />

Now that we have created both motion sprite and fixed sprite classes using our abstract Actor (fixed sprites) and<br />

Hero (motion sprites) superclasses, we need to put the code into place that will play our game audio assets. Although<br />

generally not thought of as being as important as the digital image (visual) assets, digital audio (aural) assets can be<br />

quite important to the quality of your game play. In fact, you would be surprised how much that great audio assets can<br />

add to the perceived value of your <strong>Java</strong> 8 game products. We will be learning how to optimize and implement digital<br />

audio assets for your <strong>Java</strong> 8 game development during this chapter, using open source tools such as Audacity 2.0.6.<br />

Fortunately for us, the <strong>Java</strong>FX AudioClip engine (actually, it is a class in the javafx.scene.media package) can<br />

bring a lot of power to our games development. This is because this class has essentially been designed to be an<br />

audio sequencing engine, able to control every aspect of the audio asset performance, as well as to create new audio<br />

assets using 6 octave (three up, and three down) pitch shifting capabilities. We’ll be learning about this class in<br />

detail, during the beginning of this chapter, and then implementing it in our primary InvinciBagel.java class, as well<br />

as using it in our Bagel.java class in a new .playAudioClip() method, which we’ll code and call in that class’s primary<br />

.update() method.<br />

After we look at the <strong>Java</strong>FX AudioClip class is detail, we will get into using the popular Audacity 2.0.6 digital<br />

audio editing (and audio effects) software, which we installed in Chapter 1, when we installed all of your open source<br />

game development software tools. We’ll go through an audio asset creation and optimization process using Audacity.<br />

We will use the concepts that we learned in Chapter 5 covering new media content creation concepts, and optimize<br />

digital audio files to achieve an 800% data footprint savings. We will do this so that our digital audio assets do not use<br />

more than 64KB of our system memory; in fact, we will get six 16-bit digital audio assets to use less than 62KB of data.<br />

Once we have created the six audio assets, which will match up with the six different keys that we are using to<br />

control our InvinciBagel character, we will create the .loadAudioAssets() method in the InvinciBagel class and learn<br />

how to declare AudioClip and URL objects. Inside of the .loadAudioAssets() method we will then use these two<br />

classes (objects) together in order to create our digital audio assets for the game and install them into the player’s<br />

computer system (or consumer electronics device) memory.<br />

Once these six AudioClip objects are in place, we will then have NetBeans create six Setter methods for the<br />

AudioClip objects and then “morph” these .setiSound() methods into the .playiSound() methods that we require.<br />

After this is done, we will go into our Bagel.java class, and add a .playAudioClip() method. Inside of this method, we<br />

will call the six .playiSound() methods, based upon which keys the player is pressing.<br />

We have a lot of ground to cover during this chapter, so let’s get started by taking an in-depth look at the <strong>Java</strong>FX<br />

AudioClip class and its various properties and methods that we can invoke impressive audio sequencing with! After<br />

we get that out of the way we can get into the fun stuff and start using Audacity 2.0.6 and NetBeans 8 to create!<br />

www.it-ebooks.info<br />

323

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

Saved successfully!

Ooh no, something went wrong!