Closed cory-yonomi closed 3 years ago
Are you still working on this issue?
I am
Can you post the code block? Either for the single shot/blizzard or both?
`//fire a missile this.shoot = function () { let randomAlien = Math.floor(Math.random()*alienFleet.length) shootMissile(alienFleet[randomAlien]) } let animationId const animate = () => { animationId = requestAnimationFrame(animate) // clear the canvas ctx.fillStyle = 'rgba(0, 0, 0, 0.1)' ctx.clearRect(0, 0, game.width, game.height) // render our player player.render() for (i = 0; i < barriers.length; i++){ barriers[i].render() } if (alienFleet.length == 0 && player.points <= 0) { createFleet() } else if (alienFleet.length == 0 && player.points > 1) { player.win = true displayWin() cancelAnimationFrame(animationId) } else { for (i = 0; i < alienFleet.length; i++){ alienFleet[i].render() } } aliensRemaining.innerText = alienFleet.length alien.move() missiles.forEach((missile) => { missile.render() missile.update() })
detectMissileHit()
} `
Sorry, was going back and forth between so much didn't know what to share. This fires off one missile at the very start, and no more.
Jason helped me out, got it working.
What's the problem you're trying to solve?
I'd like a random alien to fire a projectile every few seconds.
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
I can either have one shoot immediately at the start then no more, or a continuous stream of shots from random aliens, making it look like a blizzard
What is your best guess as to the source of the problem?
How my animation/game loop is being built
What things have you already tried to solve the problem?
Different locations for the alien.shoot() function with a setInterval