声音在 eclipse 中加载和播放完美,但在转换为可运行的 jar 时卡住
Sounds load and play perfectly in eclipse but get stuck when converted to a runnable jar
我正在制作游戏,但在导出游戏后,我发现我的声音停止了我的游戏。线程暂停。这是我在我的关键监听器中所做的 class:
//creating a bullet
handler.addObject(new PlayerShot1(tempObject.getX() + 58, tempObject.getY(), Id.PlayerShot1));
//changing variable to play sound
Player.shooting = true;
在我的播放器中 class:
//called every time the spacebar is pressed
if(shooting) {
GetAudio.getSound("playerShot1").play(2.0f, 0.1f);
shooting = false;
}
我已经注释掉了 GetAudio.... 行,它又开始工作了。以防万一,这是我的 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);
}
}
在此先感谢您的帮助!
而不是 "./resources/sounds/..."
,使用 "/sounds"
并将资源设为源文件夹。
我正在制作游戏,但在导出游戏后,我发现我的声音停止了我的游戏。线程暂停。这是我在我的关键监听器中所做的 class:
//creating a bullet
handler.addObject(new PlayerShot1(tempObject.getX() + 58, tempObject.getY(), Id.PlayerShot1));
//changing variable to play sound
Player.shooting = true;
在我的播放器中 class:
//called every time the spacebar is pressed
if(shooting) {
GetAudio.getSound("playerShot1").play(2.0f, 0.1f);
shooting = false;
}
我已经注释掉了 GetAudio.... 行,它又开始工作了。以防万一,这是我的 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);
}
}
在此先感谢您的帮助!
而不是 "./resources/sounds/..."
,使用 "/sounds"
并将资源设为源文件夹。