setInterval going too fast

后端 未结 2 1226
刺人心
刺人心 2021-01-22 19:26

I\'m new to JS, and decided to start of learning by a making a small game. I am using a setInterval to automate the enemy\'s attack. For their first attack the interval is corre

2条回答
  •  感情败类
    2021-01-22 19:46

    you should never use setInterval for animations!

    Just use requestAnimationFrame instead!

    • https://developer.mozilla.org/en/docs/Web/API/window.requestAnimationFrame
    • http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
    • http://css-tricks.com/using-requestanimationframe/

提交回复
热议问题