【发布时间】:2021-03-04 22:58:58
【问题描述】:
我想模拟 Spring Physics 但我不知道如何使用 PyGame 来更新 Rect。
但是当我运行我的代码时,矩形不会移动,有人可以帮我吗??? 这是我的代码:
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
【问题讨论】: