setInterval going too fast

后端 未结 2 1230
刺人心
刺人心 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:32

    You keep calling 'setInterval' again again. Each call is running in parallel.

    If you have more than one warrior peer type (archer, knight, etc), create an array that will have a separate set interval for each.

    If, as seems the case, you only have one and they play at random each turn, add clearInterval before every setInterval

提交回复
热议问题