Hi everyone.
I am creating a system with creatures that need to know when they hit each-other. At the moment I am using the following loop for each creature in each frame:
if (!_pregnant)
{
for(var i:Number = 0;i < Root.maleArray.length; i++)
{
if (this.hitTestObject(Root.maleArray*))
{
_newDNA = (Root.maleArray*._dna + _dna)/2;
_pregnant = true;
}
}
}
As these creatures breed there is quite a few by the end so the app slows greatly.
Is there a way I can listen for a collision of any two elements before I trigger the loop?
eg:
addEventListener(Event.hitTestObject, collision);
function collision(e:Event):void
{
if (!_pregnant)
{
for(var i:Number = 0;i < Root.maleArray.length; i++)
{
if (this.hitTestObject(Root.maleArray*))
{
_newDNA = (Root.maleArray*._dna + _dna)/2;
_pregnant = true;
}
}
}
}
Thank you!