声音加载并在日食中完美播放,但在转换为可运行的jar时会卡住

时间:2016-06-07 19:45:30

标签: java eclipse audio jar slick

我正在制作游戏,但在导出游戏后,我发现我的声音停止了我的游戏。线程暂停。以下是我在关键监听器类中所做的事情:

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

在我的Player类中:

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

我已经注释了GetAudio ....线,它又开始工作了。以防万一,这是我的GetAudio类:

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);
}
}

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

使用"./resources/sounds/..."而不是"/sounds",并将资源设为源文件夹。