Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why does the bullet speed up every time it's fired?

    Ok so i'm trying to make an object shoot a bullet but every time i shoot the bullet it's faster then the time before. I have no idea what's wrong with the code so if you guys have any ideas as to what's causing the bullet to speed up please tell me.

    Here's the part of the code involving the bullet.

    function keyListener(e){
    if(!e){
    e = window.event;
    }
    if(e.keyCode==32){
    fireBullet();
    }
    }
    function fireBullet(){
    bullet.style.top = 305;
    bulletTop = 305;
    bullet.style.left = playerLeft + 12;

    window.setTimeout("moveBullet();", 0);
    }
    function moveBullet(){
    bulletTop -= 4;}
    bullet.style.top = bulletTop;

    window.setTimeout("moveBullet();", 0);
    }

    Thank You,
    cgwalls

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by cgwalls View Post
    Ok so i'm trying to make an object shoot a bullet but every time i shoot the bullet it's faster then the time before. I have no idea what's wrong with the code so if you guys have any ideas as to what's causing the bullet to speed up please tell me.
    You have no condition to prevent moveBullet calling setTimeout. Think about it.


  •  

    Posting Permissions

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