ok so i've been trying to find a way that it would shoot out a projectile on command.
what i mean by this is that, my game uses a fire rate system created by @Letti42, you have to hold down the key to make it shoot (you can't just press it once or else it wont shoot), so i thought about a solution. as it turns out i dont know how to make it, that's why im asking.
(ignore the functions that are not relating to the gun's shooting)
var timer;
function startShooting(fireRate){
fireRate = fireRateEach;
if(timer)return;
timer = setInterval(function(){
createBullets();
loseBullet();
playSound("gunShot.mp3", false);
}, fireRate);
}
function stopShooting(){
setTimeout(function() {
clearInterval(timer);
timer = 0;
}, gunWentDown);
}
function createBullets(){
bullet = createSprite(player.x, player.y);
bullet.setAnimation("bullet");
bullets.add(bullet);
bullet.setSpeedAndDirection(8, player.rotation);
bullet.lifetime = 100;
}
function shooting() {
if (keyDown("space") || keyWentDown("space")) {
startShooting();
}
if (keyWentUp("space") || stage != "game") {
stopShooting();
}
}