I want to start my main game loop with surface.fill(WHITE)
to repaint my display white, but every surface from the last frame still appears.
To demonstrate, the following example blits a red surface on a green surface. The blit is created by an event trigger every 1 second. However, the red surface does not disappear when it is not being triggered by the event.
import pygame as pg
pg.init()
GREEN, WHITE, RED = (60, 120, 60), (255,255,255), (120, 60, 60)
screen = pg.display.set_mode((200, 200))
box = pg.Surface((150, 150))
box.fill(GREEN)
running = True
EVENT_SECOND_TIMER = pg.event.custom_type()
pg.time.set_timer(EVENT_SECOND_TIMER, 1000)
while running:
screen.fill(WHITE)
for event in pg.event.get():
# Draw circle every second
if event.type == EVENT_SECOND_TIMER:
surf = pg.Surface((50,50))
surf.fill(RED)
box.blit(surf, (50, 50))
screen.blit(box, (25, 25))
pg.display.update()