Set Interval is a fairly simple function that can operate separate of the timeline. Instead of counting frames, it will count milliseconds. This is useful for establishing a timer or making your game the same on all computers, regardless of framerate. Here is an example of it in use:

Timer = setInterval(function () {
seconds -=1;
}, 1000);

Okay, now to explain the code above. First of all, we are creating a new function called Timer. This function is a setInterval. Within the function the variable seconds is told to decrease by 1 every time 1,000 milliseconds goes by. So every second, the variable seconds will decrease by one. That’s it, you’ve just made your first timer.

Related posts:

  1. Code Bits: Trace
  2. Code Bits: if statements
  3. Code Bits: hitTest