Game Development Reference
In-Depth Information
Figure 15-18 . Turn .setiSound() methods into .playiSound() methods by adding calls to the AudioClip .play() method
Triggering the .playiSound() Methods in Bagel.java: The
.playAudioClip() Method
Now that we have declared, universal resource located (referenced), and instantiated
our AudioClip objects, and created .playiSound() methods that will allow us to trigger
each of these digital audio samples from “outside” of the InvinciBagel.java class, we
can go into the Bagel.java class, and write some code that allows us to trigger these au-
dio objects, to see how well the AudioClip class works. The best way to do this with
our existing code is to use the event handler code we are using to move our motion
sprite object to also allow us to trigger one of these sounds for each of the KeyEvents
that we have set up currently for our game. This is why I named these files with the
keys that they will be triggered by. The first thing that we need to put into place in the
Bagel.java class, similar to what we did in the InvinciBagel class, is a method call to a
playAudioClip() method inside of the .update() method that references an empty
private void playAudioClip() method. This method call and empty method body can be
seen in Figure 15-19 .
 
 
Search WWH ::




Custom Search