javascript game loop and game update design
- by zuo
There is a main game loop in my program, which calls game update every frame. However, to make better animation and better control, there is a need to implement a function like updateEveryNFrames(n, func).
I am considering implementing a counter for each update. The counter will be added by one each frame. The update function will be invoked according to the counter % n.
For example, in a sequence of sprites animation, I can use the above function to control the speed of the animation.
Can some give some advice or other solutions?