Results 1 to 3 of 3

Thread: Adding a delay

  1. #1
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Adding a delay

    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?

    Code:
    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.

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    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 will explain a bit more and show how to control the depth as well..
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. The Following User Says Thank You to BLiZZaRD For This Useful Post:

    crimsonsmeagol (09-09-2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Thanks Blizzard. That was exactly what I needed.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •