我正在制作游戏,但在导出游戏后,我发现我的声音停止了我的游戏。线程暂停。以下是我在关键监听器类中所做的事情:
//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);
}
}
提前感谢您的帮助!
答案 0 :(得分:1)
使用"./resources/sounds/..."
而不是"/sounds"
,并将资源设为源文件夹。