crimsonsmeagol
09-09-2008, 04:07 PM
I am wanting to add a delay so that it isn't constantly 'firing'. Right now this method is called when the spacebar is pressed, so if the user holds down the spacebar it will constantly fire. How can I add a delay to this?
function fireBullets()
{
fire = true;
_root.ship.gotoAndPlay(2);
j++;
var newname = "bullet"+j;
_root.attachMovie("bullet", newname, j*100);
_root[newname]._y = _root.ship._y+13;
_root[newname]._x = _root.ship._x+55;
_root[newname].onEnterFrame = function()
{
var bullet_speed = 7;
this._x += bullet_speed;
if (this._x>555)
{
this.removeMovieClip();
}
for (var i = 1; i<=numEnemy; i++)
{
if (this.hitTest(_root["enemy"+i]))
{
this.removeMovieClip();
_root["enemy"+i].play();
}
}
};
I know the code could use some work but I've just taken over an old project from someone else and am in the process of cleaning it up. Thanks for all your help.
function fireBullets()
{
fire = true;
_root.ship.gotoAndPlay(2);
j++;
var newname = "bullet"+j;
_root.attachMovie("bullet", newname, j*100);
_root[newname]._y = _root.ship._y+13;
_root[newname]._x = _root.ship._x+55;
_root[newname].onEnterFrame = function()
{
var bullet_speed = 7;
this._x += bullet_speed;
if (this._x>555)
{
this.removeMovieClip();
}
for (var i = 1; i<=numEnemy; i++)
{
if (this.hitTest(_root["enemy"+i]))
{
this.removeMovieClip();
_root["enemy"+i].play();
}
}
};
I know the code could use some work but I've just taken over an old project from someone else and am in the process of cleaning it up. Thanks for all your help.