Game Development Reference
In-Depth Information
Figure 15-14 . Instantiate and load the URL object, and then use it inside of the iSound0 AudioClip object instanti-
ation
The second line of code, interestingly, uses the .toString() method call, which con-
verts this URL object right back into a String object, which is required to load the Au-
dioClip() constructor method with the audio asset URL. You may be thinking: why not
use iSound0 = new AudioClip("/leftmono"); ? You can try this, however,
you'll have to “hard code” the directory, using “file:/Users/users/MyDocuments/
NetBeansProjects/InvinciBagel/src/leftmono.wav.”
I used the URL object approach so that you will be able to reference this audio file
from the inside of the JAR file, instead of using the approach shown above that re-
quires an “absolute” location on a hard disk drive. Therefore, this
getClass().getResource() method chain is adding “relative” reference data into this
URL object. Your InvinciBagel class needs this relative reference data to be able to ref-
erence your WAV audio resource files from the inside of your NetBeans 8 project In-
vinciBagel/src folder, as well as from the inside of your JAR file for your Java 8 game
application.
Next, use your trusty programmer's shortcut, and copy and paste these two lines of
code five more times underneath themselves, which is the easy way to create your oth-
er five AudioClip objects. Change the zero on both iAudioFile0 and iSound0 to iAudi-
 
Search WWH ::




Custom Search