I am trying to make a game like pong using pygame I currently have the two rectangles however one glitches I dont know why, I commented win.fill((0, 0, 0))
and it stops one of the rectangles from glitching but the other one does not this is what I have:
# import pygame module in this programimport pygame# activate the pygame library .# initiate pygame and give permission# to use pygame's functionality.pygame.init()# create the display surface object# of specific dimension..e(500, 500).win = pygame.display.set_mode((1280, 720))# set the pygame window namepygame.display.set_caption("Pong")# object1 current co-ordinatesx = 15y = 280# object2 current co-ordinatesx1 = 1245y1 = 280# dimensions of the object1width = 20height = 130# dimensions of the object2width1 = 20height1 = 130# velocity / speed of movementvel = 10# Indicates pygame is runningrun = True# infinite loopwhile run: # creates time delay of 10ms pygame.time.delay(0) # iterate over the list of Event objects # that was returned by pygame.event.get() method. for event in pygame.event.get(): # if event object type is QUIT # then quitting the pygame # and program both. if event.type == pygame.QUIT: # it will make exit the while loop run = False # stores keys pressed keys = pygame.key.get_pressed() # if left arrow key is pressed if keys[pygame.K_w] and y > 0: # decrement in y co-ordinate y -= vel # if left arrow key is pressed if keys[pygame.K_s] and y < 720-height: # increment in y co-ordinate y += vel # completely fill the surface object # with black colour win.fill((0, 0, 0)) # drawing object on screen which is rectangle here pygame.draw.rect(win, (0, 0, 255), (x, y, width, height)) # it refreshes the window pygame.display.update() keys2 = pygame.key.get_pressed() # if left arrow key is pressed if keys2[pygame.K_UP] and y1 > 0: # decrement in y co-ordinate y1 -= vel # if left arrow key is pressed if keys2[pygame.K_DOWN] and y1 < 720-height: # increment in y co-ordinate y1 += vel # completely fill the surface object # with black colour win.fill((0, 0, 0)) # drawing object on screen which is rectangle here pygame.draw.rect(win, (255, 255, 255), (x1, y1, width1, height1)) # it refreshes the window pygame.display.update()# closes the pygame windowpygame.quit()