Hi everyone!
This is my first post to the boards, so be gentle
I’m writing a small game that involves a projectile move clip checking for collision against multiple target movie clips using an array. The scene is set to 800 x 600 @ 30 fps.
My issue is my fps dropping rapidly if there are multiple projectiles in flight: there are currently anywhere from 250 - 750 target MCs (20 x 20 pixels) and 3 to 6 projectile MCs (10 x 10 pixels) in action at any given time.
The target MCs are all part of class that .push into an array onLoad:
function onLoad()
{
_root.targetArray.push(this);
_root.DEBUG_potentialTargets++; // tracking total number of targets
}
And have one function:
function destroyMe()
{
for(var i in _root.terrainArray)
{
if(_root.terrainArray* == this)
{
_root.terrainArray.splice(i,1);
_root.DEBUG_potentialTargets--;
}
}
this.removeMovieClip();
}
The projectile MC is checking every frame for a collision with anything in the root.targetArray with:
function onEnterFrame()
{
// CHECK the targetArray for collision
for(var i in _root.targetArray)
{
if(this.hitTest(_root.target*))
{
_root.targetArray*.destroyMe();
// and tell the target to remove itself
}
}
}
I’m very much an amateur coder - is there any way to optimize collision detection against such a large number of potential targets and still keep a decent framerate?