我有一个每 3 秒创建一次的矩形。
public void newRect(){
rect=Pools.obtain(Rectangle.class);
rect.set(rX, Y, 90, 90);
rectangles.add(rect);//adding to the ArrayList
}//this method gets called when condition==true
问题是我这样做时遇到错误
while(rectIterator.hasNext()){
Rectangle rect=rectIterator.next();
}//and I don't know how to make the rectangle move(all the rectangles that spawns).
在我的 Sprite 上我能够做到这一点
while(sprIterator.hasNext()){
Sprite spr=hIterator.next();
spr.draw(batch);
spr.translateY(600*deltaTime);
}
更新 初始化矩形矩形时出现错误
Exception in thread "LWJGL Application" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at java.util.ArrayList$Itr.next(ArrayList.java:851)
at com.msl.explode.Bitter.draw(Bitter.java:49)
at com.msl.explode.MyGdxGame.render(MyGdxGame.java:51)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
最佳答案
你有一个 ConcurrentModificationException
:
我建议您使用CopyOnWriteArrayList
而不是经典ArrayList
.
关于java - 如何平移矩形位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32187215/