I am creating an HTML5 canvas game for the first time. Its a tower defence game, so basically I have an array of enemy objects from class "Enemy" which fly in using a path. Then I also have an array of tower objects from a class "Tower" which kill them when they come in proximity.
For both these operations of moving multiple enemies and firing from towers I am using setInterval as below to change their states and firing animations independent of each other by using the set intervall in the instance of the respective classes. _thatTower.attackInterval = setInterval(function () ...fire code here... },50);
Difficulty I am facing is these setIntervals tend to mix up with the other instances and on few occasions combine together and play all enemy responses as one but not independent..
I want these to work independently. I have two view about this - 1. Either there is a better way to use setintetval for same class diffrent instance that i am not using. 2. OR may be setinterval is not the right thing to use at these places.. please let me know how we move many thing independently like in my case on Canvas ??
Thanks in advance