SoundStore - return store; } /** * Retrieve a sound from...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.applet.Applet; import java.applet.AudioClip; import; import java.util.HashMap; /** * A resource manager for sound effects in the game. This works with the Sound object to * organize and load all sounds for the game. * * @author Kai Lieth */ public class SoundStore { //Single instance of this class private static SoundStore store = new SoundStore(); //Cached HashMap -- Key: String, Value: Sound private HashMap<String, Sound> sounds = new HashMap<String, Sound>(); /** * Get the single instance of this class * * @return The single instance of this class */ public static SoundStore get() {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return store; } /** * Retrieve a sound from the store * * @param ref * The reference to the clip to use for the sprite (including * .wav, .au, .aiff, etc.) * @return A Sound instance containing the AudioClip */ public Sound getSound(String ref) { if (sounds.get(ref) != null) { return (Sound) sounds.get(ref); } URL url = this.getClass().getClassLoader().getResource(ref); if (url == null) { System.out.println(&quot;failed to load sound&quot;); } AudioClip newClip = Applet.newAudioClip(url); Sound newSound = new Sound(newClip); sounds.put(ref, newSound); return newSound; } }...
View Full Document

This note was uploaded on 06/10/2011 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Ask a homework question - tutors are online