Closed patrickga94 closed 2 years ago
I'm trying to get these set interval functions to fire after a certain amount of time using setTimeout but they keep going as soon as the page loads
setTimeout(moveCar1, 4000) setTimeout(moveCar2, 5000) setTimeout(moveBus1, 10000) //move the red car const moveCar1 = setInterval(()=>{ if (car1.x < -1200) {car1.x = 800} car1.x -= 20 }, 40) //move the blue car const moveCar2 = setInterval(()=>{ if (car2.x < -800) {car2.x = 800} car2.x -= 20 }, 60) //move the bus const moveBus1 = setInterval(()=>{ if (bus1.x < -1000){bus1.x = 800} bus1.x -= 20 }, 40)
Maybe because I put it under DOMContent loaded? But I though that just meant the timeout would start counting when the page loaded
nested intervals and timeouts through the wazoo
https://github.com/patrickga94/Project-1-Homie-Quest/tree/testing
Same behavior after moving setTimeouts into the game loop*
Figured it out, I was calling the intervals as opposed to passing them, so I stored those intervals in functions and passed them into the setTimeout
What's the problem you're trying to solve?
I'm trying to get these set interval functions to fire after a certain amount of time using setTimeout but they keep going as soon as the page loads
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?
Maybe because I put it under DOMContent loaded? But I though that just meant the timeout would start counting when the page loaded
What things have you already tried to solve the problem?
nested intervals and timeouts through the wazoo
Paste a link to your repository here
https://github.com/patrickga94/Project-1-Homie-Quest/tree/testing