CODE can be found at my Git Repository
Add background with lines
We want a grid, but we don’t want to draw the lines every frame. We will create a white background with lines on it using code.
#colors
white = (255,255,255)
black = (0,0,0)
#clear the display
screen.fill(white)
# Create a background
background = pygame.Surface.copy(screen)
#draw lines for the grid on the background
for y in range(0, height, 40):
pygame.draw.line(background, black, (0,y), (width,y))
for x in range(0, width, 40):
pygame.draw.line(background, black, (x,0), (x,height))
# blit the background to screen
screen.blit(background,(0,0))
We replace the
screen.fill(white)
in the loop with
screen.blit(background,(0,0))