如何翻译矩形位置?

时间:2015-08-24 16:28:39

标签: java libgdx position rectangles

我有一个每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).

在我的精灵上,我能够做到这一点

 while(sprIterator.hasNext()){
            Sprite spr=hIterator.next();
            spr.draw(batch);
            spr.translateY(600*deltaTime);
        }

UPDATE 初始化Rectangle rect时得到的错误

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)

1 个答案:

答案 0 :(得分:1)

您已获得ConcurrentModificationException: 我建议您使用CopyOnWriteArrayList代替经典ArrayList