I'm running into a problem that I've never had before. I'm hitTesting the same array against itself, but I'm now trying to remove the two objects that are colliding and replace them with one object of the same kind.
for (var i:int = Level.waterCubeArray.length - 1; i >= 0; i--){
var water = Level.waterCubeArray[i];
for (var i2:int = Level.waterCubeArray.length - 1; i2 >= 0; i2--){
var water2 = Level.waterCubeArray[i2];
if(water == water2) continue;
if(water.hitTestObject(water2)){
water.parent.removeChild(water);
water2.parent.removeChild(water2);
Level.waterCubeArray.splice(Level.waterCubeArray.indexOf(water), 1);
Level.waterCubeArray.splice(Level.waterCubeArray.indexOf(water2), 1);
water.produceCube(water);
}
}
}
"water.produceCube(water)" creates another block of water and adds it to the same array. One of the problems seems to be that the new block gets tested against the two blocks that disappear to create it. That seems to be what's happening. Also, if three blocks are hitting against each other, I get errors and other strange behavior.
Is my logic wrong on this?