2015-08-24 66 views
0

我有一個每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 錯誤,我得到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) 
+2

做到這一點'Rectangle = rectIterator.next()'是故意的嗎?或者你試圖說'Rectangle rec = recIterator.next()'? –

+0

ohh對不起,我會編輯 –

+0

你會得到什麼樣的錯誤?發佈stacktrace或logcat –

回答