Hi guys
I'm trying to remove enemies from an array list when they pass off the screen by using the objects.index value, removing that from the arrayList, then looping through copying al the neccesary ones back into an Array (to modify their index values appropriately) and then back into the arrayList but im having some problems
The speed seems to increase and while it does seem to work (keeping the arraylist size down) im not sure, any help would be great thanks!
I'm trying to remove enemies from an array list when they pass off the screen by using the objects.index value, removing that from the arrayList, then looping through copying al the neccesary ones back into an Array (to modify their index values appropriately) and then back into the arrayList but im having some problems
The speed seems to increase and while it does seem to work (keeping the arraylist size down) im not sure, any help would be great thanks!
- void update() {
ypos += speed;
if(ypos > height){
println(index + " - " + waveIndex + " - " + waves.size());
//if(index>1){
// waves.remove(int(index-2));
//}else{
// waves.remove(int(index-1));
// }
Wave[] wavesTemp = new Wave[waves.size()-1];
wavesTemp = waves.toArray(wavesTemp);
for(int i = int(index); i < waves.size()-1; i++){
wavesTemp[i] = wavesTemp[i+1];
wavesTemp[i].index = i;
}
waves.remove(index);
for(int i = 0; i < waves.size(); i++){
waves.set(i,wavesTemp[i]);
} - }
1