diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2023-06-06 23:22:47 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2023-06-06 23:22:47 -0400 |
commit | 9b7cad1006eced84d3b81d52173759ba709245a2 (patch) | |
tree | 052d3172860fd4a2157664e12606d84d1ea45b19 /src/main/SoundController.java | |
parent | 49ccb5c20aa84501c1ed6b534bfa00a4a9dc5902 (diff) | |
download | NPEhero-9b7cad1006eced84d3b81d52173759ba709245a2.tar.gz NPEhero-9b7cad1006eced84d3b81d52173759ba709245a2.tar.bz2 NPEhero-9b7cad1006eced84d3b81d52173759ba709245a2.zip |
fix sound and project cleanup
Diffstat (limited to '')
-rw-r--r-- | src/main/SoundController.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main/SoundController.java b/src/main/SoundController.java index c8e6c8a..8f255da 100644 --- a/src/main/SoundController.java +++ b/src/main/SoundController.java @@ -6,6 +6,7 @@ import java.util.HashMap; import gui.Driver; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; +import javafx.util.Duration; public class SoundController { @@ -14,6 +15,9 @@ public class SoundController private HashMap<String,MediaPlayer> effects = new HashMap<>(); private File mainMenuSong = new File("src/assets/fairyfountain.wav"); + /** + * creates a new sound controller and starts playing the main menu music + */ public SoundController() { effects.put("hit", new MediaPlayer(new Media(new File("src/assets/hit.wav").toURI().toString()))); @@ -26,6 +30,10 @@ public class SoundController playMenuSong(); } + /** + * plays the song that is passed in. + * @param songFile: the song + */ public void playSong(File songFile) { if (songMediaPlayer != null) @@ -38,6 +46,9 @@ public class SoundController songMediaPlayer.play(); } + /** + * plays the main menu song + */ public void playMenuSong() { playSong(mainMenuSong); @@ -45,6 +56,9 @@ public class SoundController songMediaPlayer.play(); } + /** + * stops the currently playing song + */ public void endSong() { if (songMediaPlayer != null) @@ -53,9 +67,15 @@ public class SoundController } } + /** + * plays a sound effect + * for the volume slider to take affect each mediaplayer needs to be pre loaded. + * this rewinds and played the proper mediaplayer for the sound + * @param preset: a string of the name of the sound. possible sounds assigned in the constructor + */ public void playSfx(String preset) { - effects.get(preset).stop(); + effects.get(preset).seek(new Duration(0)); effects.get(preset).play(); } }
\ No newline at end of file |