Merge remote-tracking branch 'origin/master'
commit
a2aa091af0
Binary file not shown.
|
@ -2,7 +2,10 @@
|
|||
// displays dialogue, animates dialogue, and renders box that contains dialogue as well as the portraits of the characters
|
||||
// that speak to the players
|
||||
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -101,6 +104,12 @@ public class DialogueMenu extends TextBox implements Serializable {
|
|||
if (frameCounter >= FREQUENCY) {
|
||||
frameCounter -= FREQUENCY;
|
||||
currentFrame += 1;
|
||||
// play dialogue sound
|
||||
try {
|
||||
UtilityFunction.playSound("sound/pen.wav");
|
||||
} catch (UnsupportedAudioFileException | LineUnavailableException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// set font of string to be drawn
|
||||
g.setFont(font);
|
||||
|
|
|
@ -22,8 +22,7 @@ public class Sound implements Serializable {
|
|||
clip.start();
|
||||
}
|
||||
|
||||
// while close() is not used because the same sounds are either constantly used or immediately dereferenced (and therefore collected by the GC)
|
||||
// it is still good practice to enable closing sounds after finishing using them
|
||||
// close sound after use
|
||||
public void close() {
|
||||
clip.close();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Eric Li, Charlie Zhao, ICS4U, Finished 6/20/2022
|
||||
// Utility functions to help with common tasks
|
||||
|
||||
import javax.sound.sampled.LineEvent;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
@ -45,6 +46,12 @@ public final class UtilityFunction {
|
|||
// start playing a sound that is located at filePath
|
||||
public static void playSound(String filePath) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
|
||||
Sound sound = new Sound(filePath);
|
||||
sound.clip.addLineListener(e -> {
|
||||
// close clip after sound is done playing
|
||||
if (e.getType() == LineEvent.Type.STOP) {
|
||||
sound.close();
|
||||
}
|
||||
});
|
||||
sound.start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue