1
import time
import sys
import random
import pygame

#Variables
white = (255,255,255)
simStart = True
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
x = 590.575
y = 450
clock = pygame.time.Clock()

pygame.init()

screen = pygame.display.set_mode((1200,600))

pygame.display.set_caption("Squirrel Problem")

screen.fill(white)

pygame.display.update()

while simStart == True:
    while x > 1:
        for event in pygame.event.get():
            if (event.type==pygame.QUIT):
                pygame.quit()

        screen.fill(white)

        pygame.draw.rect(screen, red, (300, 50, 600, 291.53))
        pygame.draw.rect(screen, blue, (x, y, 18.85, 55.81))

        x = x - .5
        clock.tick(30)
        pygame.display.update()

When I run the code, the screen will flicker. I've heard that this is because of screen.fill() but I don't know another way to clear the last position of [pygame.draw.rect(screen, blue, (x, y, 18.85, 55.81))]. Does anyone know how to do this without the screen glitching/flickering?

Rob B.
  • 15
  • 3

0 Answers0