Hi everyone I hope I asked the correct question. So Basically I have a Movie Clip named mcLiquidWaste
that I add to the stage. There are 3 different positions on the stage that they come out of. In my main engine class I have a for loop set up that controls how many come out at a time like so:
private function addLiquidWaste():void
{
//Duplicate Tween for repeat
TweenLite.delayedCall(randomNumber(nDifficulty1, nDifficulty2), addLiquidWaste);
//determine how many come out at a time
numberOfLiquids = randomNumber(1, 3);
//iterate through for loop
for (var i = 0; i < numberOfLiquids; i++)
{
//Instantiate liquid
var liquid:mcLiquidWaste = new mcLiquidWaste();
//Add liquid to stage
stage.addChild(liquid);
//push liquid MC into array
aLiquidArray.push(liquid);
}
}
The issue I am having is that sometimes when they come out they overlap each other for instance say 3 come out at the same time well 2 of those might come out in the same position which I dont want. I want to somehow process that if they come out in the same position and not in a different slot on the stage then have them removed or have the overlapping movie clip go to a different position. That is why I was thinking of checking if 2 of the objects in the array are touching then remove those somehow.
Here is what my mcLiquidWaste
class looks like and how they are added to the stage in different positions.
private function init():void
{
nSpeed = 4;
var liquidPosition:Number = randomNumber(1, 3);
if (liquidPosition == 1) //Position Lava to the Left Hole
{
this.y = (stage.stageHeight / 2) - 200;
this.x = (stage.stageWidth / 2) - 150;
}
if (liquidPosition == 2) //Position Lava to the Middle Hole
{
this.y = (stage.stageHeight / 2) - 200;
this.x = (stage.stageWidth / 2) ;
}
if (liquidPosition == 3) //Position Lava to the Right Hole
{
this.y = (stage.stageHeight / 2) - 200;
this.x = (stage.stageWidth / 2) + 150;
}
addEventListener(Event.ENTER_FRAME, liquidHandler);
}
as you can see in my liquid waste class they are added to the left, middle, and right of the stage. Please ANY help would be appreciated thank you!
How I managed to fix it
for (var a:int = 0; a < aLiquidArray.length - 1; a++)
{
var l1:mcLiquidWaste = aLiquidArray[a];
for (var j:int = a + 1; j < aLiquidArray.length; j++)
{
var l2:mcLiquidWaste = aLiquidArray[j];
if (l1.hitTestObject(l2))
{
//do something on collision
l2.destroyLiquid();
}
}
}