# How to display consistent background image

Drawing a large background is relatively slow in PyGame. In order to avoid drawing BG every frame, you could draw it once, then do nothing.

However, if something is overdrawn onto the surface and keeps moving, you will need to redraw the background in order to "erase" the color pixels left by moving object; otherwise, you will have "traces" of the moving object.

I have a moving object in my PyGame. However, I do not want to "clear the color buffer" by redrawing the background image. Redrawing the background image every frame is slow.

My solution :

I will "clear" only required portions (where the "traces" of moving object are left) of the "buffer" by redrawing portions of background.

Is there any other better way to have a consistent background?

• Re-drawing the BG each frame shouldnt be too slow, are you calling convert_alpha() when you load the image? – Serial May 12 '14 at 22:50
• I am. conver_alpha() had significantly improved performance of my game. However I still want to squeeze out more frames because I want to add more stuff moving around in the game. However my solution to squeeze out more frame by "partical rerendering background" is not good enough. I am wondering if there was other techniques that I can pull more frames that's not "partial rerendering background" – Tofu_Craving_Redish_BlueDragon May 13 '14 at 7:34

2. Get their bounding boxes, before they move. Call this list of boxes B.
3. For each box b in B, check if b is intersecting bounding boxes of objects that aren't moving. If it is, union those the boxes (including b) and replace b with this new rectangle.
4. Redraw all the portions of the background defined by the rectangles in B, as well as all the entities to which those rectangles belong.