mardi 5 juin 2018

Is there any way to check the game over condition in each of the timeouts but calling the main function to restart the game by a single function

I am making a game in which I have 5 players each being moved with a setTimeout which repeats after calling another setTimeout. However, when the game gets over i need to stop all the current timeouts and call the main function to start game again. Since the hero can get killed by touching any of the villains I have to check this condition of their timeouts. If this condition is met in any of the timeout, all timeouts are cleared and main function is called to start game again.

Problem: However many of the timeouts are still going on in the background. Is there any way to check the game over condition in each of the timeouts but calling the main function by a single function because I think that since all the timeouts having the main function call in the code many calls to the main function is made.




Aucun commentaire:

Enregistrer un commentaire