Background vs sprite background with loops


I got my students to understand why we need to put the “background” code in the loop, by explaining how the loop works with a counter pattern and showing the difference when a sprite moves with the background in and out of the loop.

However using a sprite as the background, we do not put that in the loop, and it works fine without the duplicate image streak that happens when the “background” code is not in there. can someone clarify the difference between them and why it does not happen with the sprite background.


So, even if you don’t create the background sprite inside the draw loop, I assume you are using the “drawSprites” block inside the loop. This block draws all sprites each time through the loop. This includes sprites created inside or outside of the loop.

Best practice would be to create all sprites outside the loop and only update them inside the loop. In the case of a background sprite, you aren’t changing the x or y value of the sprite ever, but it is still redrawn every time the drawSprites block is called.

With a normal background block, it is only called repeatedly if it is inside the loop.

Hope that make sense!


Ahhhhh thank you!! that makes sense, I forgot how the drawsprite code works which would redraw every sprite above it again, not just what’s in the loop. I really appreciate the response!!

Thank you!