Closed DG-98 closed 3 years ago
I want the game to end when lives hit 0
let gamePlay = () => { ctx.clearRect(0, 0, gameArea.width, gameArea.height) bob.render() // green.render() // bomb.render() // green.y += descent bomb.y += descent itemSpawned.forEach((items) => { items.render() items.y += descent }) bombSpawned.forEach((bomb) => { bomb.render() bomb.y += descent }) hitbox() bombHit() scoreTracker() lifeTracker() // if (lives = 0) { // cancelAnimationFrame(gamePlay) // } requestAnimationFrame(gamePlay) }
I need a way to end requestAnimationFrame
I've tried using if (lives =0) {cancelAnimationFrame} but that only sets the lives variable to 0 and it doesn't end the game when hit.
look up how you can manipulate size with things like .fillText and .style
figure out how to manually end game since cancelAnimationFrame isn't working (or ask a classmate who has used it)
What's the problem you're trying to solve?
I want the game to end when lives hit 0
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?
What is your best guess as to the source of the problem?
I need a way to end requestAnimationFrame
What things have you already tried to solve the problem?
I've tried using if (lives =0) {cancelAnimationFrame} but that only sets the lives variable to 0 and it doesn't end the game when hit.