I am using libgdx, I have a class class created by me. I am trying to remove balls of the same color at a time. due to a shift in the position of the elements in the array after deleting the element, this leaves some element restored. so I use Snapshot Arrays
https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/SnapshotArray.html
according to the size of the documentation array and indexes it will not change if we write our loop between the array.begin () and array.end () methods. so I declared snapshot arrays
SnapshotArray<Ball> balls;
and my removal method
private void removeVillianGroups(int color){
Ball[] ball=balls.begin();
for(int i=0;i<balls.size;i++){
if(balls.get(i).getColor()==color){
ball.removeValue(balls[i],true);
}
}
balls.end();
}
and I get an error when casting
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lcom.mygames.haloween.Entity.Ball;
on this line above
Ball[] ball=balls.begin();
So, I created my array, basically I divide my screen width into six equal parts to have 6 columns of balls
private void createVillians() {
for (int color=0;color<4;color++)
for(int i=0;i<6;i++)
{
balls.add(new Ball(viewport,new Vector2(i*viewport.getWorldWidth()/6,
0-c*viewport.getWorldWidth()/6),color));
}
}
