...

View Full Version : Why does the bullet speed up every time it's fired?



cgwalls
10-03-2008, 02:35 AM
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

Arty Effem
10-03-2008, 02:50 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum