Iterating through an array with a timer - almost there?

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


that might be confusing at first, but lets take it like this:
processing has 2 modes,

  • paint mode
  • draw mode

in paint mode you never do a background(…)
so all you draw will be over other drawings.

in draw mode you clean the canvas with background(…) ( 60 times per second )
and draw what you want to show
in that case all the array up to the current point ( by the timer )


so your draw loop should be like (untested)

void draw () {
  background (200);
  for ( int i = 0; i < counter; i++ ) tigergoogle[i].display ();

  if (millis() - lastTime >= timeUntilNext) {
    counter = ++counter % tigergoogle.length;
    lastTime = millis();
  }
}

1 Like