我如何让我的形状移动?我希望它使用提供的 while 语句移动

How do i get my shape to move? I want it to move using the while statement provided

pygame.draw.circle(screen, btms3, (250, 187.5), 125, 2)
pygame.display.update()

x=10
y=10
running = 1

while running:
  if x <=10:
    hmove = 1
  elif x >= 350:
   hmove = -1
  if hmove == 1:
    x += 1
  elif hmove == -1:
    x += -1

如何做到如标题所说的那样? 我确实有 pygame 翻转和显示更新和类似的东西,但我不能显示,因为我不想有一个超长的代码。

您必须在应用程序循环中移动对象,并且必须在每个 frame.Change 循环中圆的中心坐标中重新绘制场景,并在每一帧中的新位置绘制圆:

import pygame

pygame.init()
screen = pygame.display.set_mode((360, 360))
clock = pygame.time.Clock()
x, y, hmove = 10, 10, 1

run = True
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False 

    x += hmove
    if x >= 350 or x <= 10:
        hmove *= -1

    screen.fill((0, 0, 0))
    pygame.draw.circle(screen, "red", (x, y), 10, 2) 
    pygame.display.update()
    clock.tick(100)

pygame.quit()
exit()

典型的 PyGame 应用程序循环必须: