How often to swap buffers?

How often must one swap buffers in SmartMatrix? In the FeatureDemo, the command is used 77 times.
I wrote 4-5 lines of code to create rectangles and swapped buffers once. How many more lines can I add. Should the buffer be swapped after every backgroundLayer call? What’s the “rule of thumb” ?

Swap the buffers each time you have finished preparing one single frame of animation.

If you want your rectangles to displayed one-by-one. swap buffers after each one. Maybe delay(100) too to slow it down a bit.

If you want to plot 5000 rectangles, and only swap buffers when they’re all plotted, that is fine too. Or you could try to find a balance and plot 10 rectangles between swaps.

When you call it is driven only by what you want to appear on the LEDs. SmartMatrix makes no demands.

THanks, good info. I’m displaying two flags with a “wipe” in between. The flags will be static (although I may animate later to make it flutter in the wind). So the demands aren’t great. I did experiment a bit with swapping buffers in the middle of my creation but what seems to be the best is make all the rectangles, lines and pixels, the swap buffers. Looks pretty good.