My applet creates a new sound every time an impact occurs, which is very frequently.
How come, when the sounds become too numerous, the game ceases to run smoothly?
Here is the code that gets called many, many times:
class soundThread extends Thread
{
String sound;
soundThread(String i_sound)
{
sound = i_sound;
}
public void run()
{
try{
URL path = new URL(getClass().getProtectionDomain().getCodeSource().getLocation(), sound+".wav");
AudioClip clip = Applet.newAudioClip(path);
//checkpoint A
clip.play();
//checkpoint B
}catch(Exception e){System.err.println("err= soundThread_error");e.printStackTrace();}
}
}
The longest pause occurs at clip.play();
. Any clue why it would take so long to play the clip? And how can I fix it?