beforeRender iteration control

How do I use the delta variable to change the rate at which beforeRender is called. This must be simple, so say I want to change my pixel array contents every 0.5 secs?

Do I compare the current value of delta with a prior value +500 or …

Hi,
The delta parameter is the number of milliseconds that have past since the last beforeRender() was called. If you want to know when .5 seconds or 500ms have past, you can accumulate deltas until it adds up and reaches that amount. The “Example: modes and waveforms” pattern does just that for 600ms. Adapted here:

var timer
export function beforeRender(delta) {
  timer += delta // accumulate all the deltas into a timer
  if (timer > 500) { // after 500ms, do something
    timer -= 500 //take 500ms off the timer
    //insert your code here that will run every half a second
  }
}
1 Like