如何解决PyGame Rect 更新但不会在我的 while 循环中移动?
我想模拟 Spring Physics,但我不知道如何使用 PyGame 来更新 Rect。
但是当我运行我的代码时没有任何作用,矩形不会移动有人可以帮助我吗??? 这是我的代码:
maxmag = 100
mag = 100
screen.fill((255,255,255))
ball = pygame.draw.circle(screen,(0,255),(250,250 + mag),75)
cube = pygame.draw.rect(screen,0),pygame.Rect(250,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,250 + mag))
cube.update(pygame.Rect(250,250 + mag))
#cube = pygame.draw.rect(screen,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,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()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。