Trying to delay shooting in a game, the action is done by clicking but currently, it shots every frame while holding click.
SetTimeInterval does not work in my case since it just loops the function SetTimeout does not work as well because it stops the function the second it's played and after the interval. Tried a sleep function but it freezes up the code while running
//sleepcode
var sleep = function(delay) {
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
//called by:
if(self.pressingAttack){
self.shootBullet(self.mouseAngle);
sleep(3000);
}
I want a function that shots the second its clicked but delays the second bullets, similar to every shooting game ever.