PyGame 矩形更新但不会在我的 while 循环中移动?

PyGame Rect Updates But Won't Move In My while Loop?

我想模拟 Spring 物理,但我不知道如何使用 PyGame 来更新矩形。

但是当我 运行 我的代码不起作用时,矩形不会移动有人可以帮助我吗??? 这是我的代码:

maxmag = 100
mag = 100

screen.fill((255, 255, 255))
ball = pygame.draw.circle(screen, (0, 0, 255), (250, 250 + mag), 75)
cube = pygame.draw.rect(screen, (0, 255, 0), pygame.Rect(250,0,10,250 + mag))

while running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    mag -= 1
    if mag <= -maxmag:
        maxmag -= 10
        mag = maxmag

    cube = pygame.draw.rect(screen, (0, 255, 0), pygame.Rect(250,0,10,250 + mag))
    cube.update(pygame.Rect(250,0,10,250 + mag))
    #cube = pygame.draw.rect(screen, (0, 255, 0), pygame.Rect(250,0,10,250 + mag))

    print(mag)

    clock.tick(60)

    pygame.display.flip()

pygame.quit()

感谢阅读:D

这是动画与 pygame 的工作方式:

import pygame

pygame.init ()
screen = pygame.display.set_mode ((600, 400))
clock = pygame.time.Clock ()

x_step = 2
y_step = 2
x = y = 100
running = True
while running :
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    screen.fill ((255, 255, 255))
    pygame.draw.rect(screen, (0, 255, 0), pygame.Rect(x,y,50,50))
    x += x_step
    if x > 550  or x < 0 : x_step = -x_step
    y += y_step
    if y > 350 or y < 0 : y_step = -y_step
    pygame.display.flip()
    clock.tick (70)

pygame.quit()