import pygame
pygame.init()
screen = pygame.display.set_mode((1600,900))
red=(255,0,0)
blue=(0,0,204)
white=(255,255,255)
pygame.display.set_caption("Orbit")
gameLoop=True
clock=pygame.time.Clock()
while gameLoop:
dy=10
dx=10
x=600
y=250
for event in pygame.event.get():
if (event.type==pygame.QUIT):
gameLoop=False
x=x +dx
y=y +dy
screen.fill(white)
pygame.draw.circle(screen,red,[800,450],50,0)
pygame.draw.circle(screen,blue,[x,y],10,0)
pygame.display.update()
clock.tick(50)
pygame.quit()
我在这里编写了这个有两个圆圈的代码,我希望得到一个(较小的一个)在屏幕上循环但是由于某种原因它不动,我不知道我做错了什么我已经阅读并搜索了一些对我没那么帮助的东西。非常感谢任何建议,谢谢你的时间
答案 0 :(得分:2)
您的x
和y
值是在游戏循环中定义的,因此,即使您正在向他们添加dx
和dy
,您也可以#39 ;每帧重新将它们重置为原始值。
如果您将x=600
和y=250
移至while循环之前,它将开始移动。