I am creating a simple game and whenever i shoot bullets, the game becomes VERY laggy. I have a movieclip for bullets and i use an array to control it. Here is the code that i have in my MAIN file:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class main extends MovieClip
{
private var _enemy:Number;
private var _bullets:Array;
private var _damage:Number;
public function main()
{
_enemy = 10;
_damage = 5;
_bullets = new Array();
_bullets = [];
stage.addEventListener("bulletCreated", onBulletCreated);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onBulletCreated(event:Event)
{
_bullets.push(MovieClip(event.target));
trace(event.target.name);
}
public function onEnterFrame(event:Event):void
{
for (var j:int = 0; j < _bullets.length; j++)
{
//Top
if (_bullets[j].hitTestObject(enemy))
{
removeChild(_bullets[j]);
_bullets.splice(j,1);
j--;
}
}
}
public function checkCollisionWithPlayer(wall:MovieClip)
{
Collision.block(player, wall);
}
}
}
Any suggestions as to why the game is so laggy?