我试图重新创建AngryBirds的开始画面,其中有背景中有射弹射击。我用以下代码尝试了slick2d
public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException {
for (int a = 0; a < delta; a++) {
if (pros.size() < 5) {
pros.add(new MenuProjectile(Images.red[0]));
}
pros.iterator().forEachRemaining(p -> {
if (p.getX() > gc.getWidth() || p.getY() > gc.getHeight()) {
pros.remove(p);
} else {
p.update();
}
});
}
}
而slick2d给了我错误
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909)
at java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:904)
at startmenu.Menu.update(Menu.java:29)
at org.newdawn.slick.state.StateBasedGame.update(StateBasedGame.java:266)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at state.Angrybird.main(Angrybird.java:29)
Thu Mar 29 21:07:04 SGT 2018 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:669)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at state.Angrybird.main(Angrybird.java:29)
enter code here
假设如果我使用迭代器,则不应抛出此错误。请帮忙!