Normally you will do:
def draw():
# fill screen with solid color.
# draw, and flip/update screen.
But, you can update just dirty portions of the screen. See pygame.display.update()
:
pygame.display.update()
Update portions of the screen for software displays
update(rectangle=None) -> None
update(rectangle_list) -> None
This function is like an optimized version of pygame.display.flip() for software displays. It allows only a portion
of the screen to updated, instead of the entire area. If no argument
is passed it updates the entire Surface area like
pygame.display.flip().You can pass the function a single rectangle, or a sequence of rectangles. It is more efficient to pass many rectangles at once than
to call update multiple times with single or a partial list of
rectangles. If passing a sequence of rectangles it is safe to include
None values in the list, which will be skipped.
It’s best to use it in combination with RenderUpdates
, which is a Sprite.Group
:
pygame.sprite.RenderUpdates
Group sub-class that tracks dirty updates.
RenderUpdates(*sprites) -> RenderUpdates
This class is derived from pygame.sprite.Group(). It has an extended draw() method that tracks the changed areas of the screen.