我创建了一个libdx游戏,它在Android和桌面版本中均可正常运行。在游戏中,我有一只飞来飞去的鸟,必须避开其他物体。如果它接触到对象,则游戏结束,并且出现游戏结束屏幕。
在我的GWT应用程序中,第一次在屏幕上出现游戏时我没有问题,但是如果我重新启动游戏并再次玩游戏,则会收到错误消息:
在Google Chrome控制台中,该错误发生在javascript的“ throw new RuntimeException(t)
”行中。我不太熟悉Javascript。动画调度程序之前是否有人遇到过类似的问题?
AnimationScheduler.get().requestAnimationFrame(new AnimationCallback() {
@Override
public void execute (double timestamp) {
try {
mainLoop();
} catch (Throwable t) {
error("GwtApplication", "exception: " + t.getMessage(), t);
throw new RuntimeException(t);
}
AnimationScheduler.get().requestAnimationFrame(this, graphics.canvas);
}
}, graphics.canvas);
}
在我的Libgdx核心代码中,当小鸟坠毁且游戏结束时,将调用以下行代码,因此很可能在发生错误的地方:
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
Sounds.gameOverSound.play(SettingsManager.gameVolume);
highScore.stopCounting();
for (Dodgeable dodgeable : dodgeables.activeDodgeables) {
dodgeable.reset();
}
dodgeables.resetSpawnTimes();
for (Sound sound : Sounds.activeSounds){
//Stop all sounds currently playing
sound.stop();
Sounds.activeSounds.remove(sound);
}
//Reset all notifications that are active so they stop displaying
Notifications.ExclamationMark.resetNotifications();
Array<Body> bodies = new Array<Body>();
world.getBodies(bodies);
for (int i = 0; i < bodies.size; i++) {
world.destroyBody(bodies.get(i));
}
dispose();
game.setScreen(new GameOverScreen(game, playServices, databaseAndPreferenceManager, highScore));
}
});
答案 0 :(得分:1)
解决了这个问题……事实证明,在我的“ dispose()”方法中,我正在处置另一个类中的Sound,而不是重新创建Sound。因此,我正在处理导致错误的空声音。