android - LibGDX- removing items from screen on collision -


i trying remove items screen when reach height. render method below. other parts of code seem work, when items specified height, instead of removing them , rendering next frame, error shown.

    batch.begin();     gdx.gl.glclearcolor(1, 1, 1, 1);     gdx.gl.glclear(gl20.gl_color_buffer_bit);      t = gdx.graphics.getdeltatime();     time += t;     speed = 300;      if (time >= ((height / speed)/4)) {         time = 0;         onscreenqueue.add(spawnblock(speed));     }     batch.draw(new textureregion(square.gettexture()),square.getposx(), square.pos.y, padding, padding);      (shapes : onscreenqueue) {          batch.draw(new textureregion(i.gettexture()), i.pos.x, i.pos.y -= speed * t, padding, padding);          if (i.pos.y <= h) {             if(i.getside() == square.getside()){                 onscreenqueue.remove(i);             }         }      }     batch.end(); 

it's because removing items list, while iterating through it. results in concurrentmodificationexception.
avoid this, might use iterator:

    (iterator<shape> iterator = onscreenqueue.iterator(); iterator.hasnext();) {         shape = iterator.next();         batch.draw(new textureregion(i.gettexture()), i.pos.x, i.pos.y -= speed * t, padding, padding);          if (i.pos.y <= h) {             if(i.getside() == square.getside()){                 iterator.remove();             }         }     } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -