Timers for Animation
Goal for the Day.
- This is a side trip.
- And fairly shallow at that.
- Most operating systems support the idea of timers.
- After an interval has elapsed a function is called.
- This is then easily extended to programs.
- Javascript support two basic tools for this
- In either case, they take
- A function to be called
- An optional time, in milliseconds to wait until the function is called
- If this is 0 (or not given), the function is called immediately
- Or, better yet, at the bottom of the next event loop.
- The delay may be longer than the given delay
- A set of optional arguments.
- Either case, they return a timer id.
- This can be used to cancel the timer
- You really only want one timeout/interval running for your main animation.
- If you set multiple timers, with the same callback function, it will try to do it.
- Which will nullify your delay.
- Think reseeding the random number generator , but worse
- And you really want that callback function to finish in less than the delay given.