我正在尝试生成多个矩形,这些矩形在屏幕上平移,任意两个连续矩形之间的间隔距离不同。
这是代码片段-
win = pygame.display.set_mode((500, 500)) #canvas size is 500x500
width = 40
height = 60
x = 500 - width
y = 500 - height
vel = 5
state = True
while(state):
pygame.time.delay(50)
x -= vel
pygame.draw.rect(win, (0, 0, 255), (x, y, width, height))
pygame.display.update()
#I have not included the pygame exit code
Run Code Online (Sandbox Code Playgroud)
现在,我该如何解决这个问题,而不会在每次尝试生成新矩形时都使矩形消失?