Game Development Reference
In-Depth Information
Figure 15-13 . Create the private void .loadAudioAssets() method to hold the AudioClip object instantiation state-
ments
Inside of your .loadAudioAssets() method body, your will have two Java code
statements, as loading a digital audio asset is a little bit more involved than referencing
digital image assets. First, you will load your first iAudioFile0 URL object, using the
getClass().getResource() method chain. This method chain loads the URL (uniform
resource locator) object with the digital audio sample resource that you want to use,
and will do this for your Class object (in this case, this is the InvinciBagel class, since
that is the Java class which we are writing this code in).
The resource that you are looking to get the URL for goes inside of the .getRe-
source() method call, and uses the same format as the resource references that you used
for your digital image assets, which in this case would be a “/leftmono.wav” file refer-
ence, which is converted by the .getResource() method into a binary URL data format.
This Java code can be seen in Figure 15-14 , and looks like the following Java method
body:
private void loadAudioAssets() {
iAudioFile0 = getClass().getResource ("/leftmono.wav");
iSound0 = new AudioClip(iAudioFile0 .toString() );
}
 
Search WWH ::




Custom Search