Log in

View Full Version : Adding a delay



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.

BLiZZaRD
09-09-2008, 04:31 PM
Just need to give a new var to count the bullets, something like var bulletCount = 1;

then run an if loop to check for a number, if number is > set number disable the fire key.

this old tutorial (http://www.flashkit.com/tutorials/Games/Building-David_Do-611/index.php) will explain a bit more and show how to control the depth as well..

crimsonsmeagol
09-09-2008, 05:08 PM
Thanks Blizzard. That was exactly what I needed.