2

I am making a game but having exported it, I found that my sounds stop my game. The thread pauses. Here is what I'm doing in my key listener class:

//creating a bullet
handler.addObject(new PlayerShot1(tempObject.getX() + 58, tempObject.getY(), Id.PlayerShot1));
//changing variable to play sound
Player.shooting = true;

And in my Player class:

//called every time the spacebar is pressed
if(shooting) {
    GetAudio.getSound("playerShot1").play(2.0f, 0.1f);
    shooting = false;
}

I have commented out the GetAudio.... line and it started working again. Just in case, here is my GetAudio class:

public class GetAudio {

public static Map<String, Sound> soundMap = new HashMap<String, Sound>();
public static Map<String, Music> musicMap = new HashMap<String, Music>();

public static void get() {
    try {
        soundMap.put("playerShot1", new Sound("./resources/sounds/playerShot1.ogg"));
    } catch (SlickException e) {
        e.printStackTrace();
    }
}

public static Music getMusic(String key) {
    return musicMap.get(key);
}

public static Sound getSound(String key) {
    return soundMap.get(key);
}
}

Thanks in advance for your help!

TheChubbyPanda
  • 1,721
  • 2
  • 16
  • 37
  • Depending on how you setup your project folder, some files might be moved around. explore the jar file with something like WinRar to see where the jar is placing the files. – xes_p Jun 07 '16 at 19:46
  • I know for a fact that it is finding the sound because there are other sounds that work. Its playing it that is the issue. – TheChubbyPanda Jun 07 '16 at 19:48
  • problem is here `new Sound("./resources/sounds/playerShot1.ogg")` you are using relative route that eclipse can find, but not in jar, please kindly check http://stackoverflow.com/a/270398/3850595 – Jordi Castilla Jun 07 '16 at 19:49
  • maybe this is clearer http://www.mkyong.com/java/java-read-a-file-from-resources-folder/ `I <3 mkyong` – Jordi Castilla Jun 07 '16 at 19:57
  • I can load my images from there so why not my sounds? – TheChubbyPanda Jun 07 '16 at 20:09

1 Answers1

1

Instead of "./resources/sounds/...", use "/sounds" and make resources a source folder.

TheChubbyPanda
  • 1,721
  • 2
  • 16
  • 37