[英]image move in pygame (crashes pygame)
i'm trying to make a game and when this loop runs, it crashes pygame 我正在尝试制作一个游戏,当此循环运行时,它使pygame崩溃
while poterbar_hunt_pone == True and ptwo_shot == True:
if poterbarx < xone+carone_width:
poterbar_dir = "right"
poterbarx_c = 20
else:
poterbar_dir = "left"
poterbarx_c = -20
if poterbary+poterbarh < yone:
poterbary_c = 20
else:
poterbary_c = -20
if poterbarx <= xone+carone_width and poterbarx+poterbarw >= xone:
if poterbary+poterbarh >= yone and poterbary <= yone+carone_height:
xone_change = random.randrange (-20, 20)
yone_change = random.randrange (-20, 20)
poterbar_hunt_pone = False
ptwo_shot = False
poterbarx = -100
poterbary = -100
when both values are True pygame crashes and i think is in the movement of poterbar. 当两个值都为True pygame崩溃时,我认为是在poterbar的运动中。 if anyone of you guys know about what causes pygame to crash please let me know
如果你们当中有人知道pygame崩溃的原因,请告诉我
You are missing pygame.display.update()
. 您缺少
pygame.display.update()
。
Add this at the very bottom of your code, so now it looks like: 将其添加到代码的最底部,现在看起来像:
while poterbar_hunt_pone == True and ptwo_shot == True:
if poterbarx < xone+carone_width:
poterbar_dir = "right"
poterbarx_c = 20
else:
poterbar_dir = "left"
poterbarx_c = -20
if poterbary+poterbarh < yone:
poterbary_c = 20
else:
poterbary_c = -20
if poterbarx <= xone+carone_width and poterbarx+poterbarw >= xone:
if poterbary+poterbarh >= yone and poterbary <= yone+carone_height:
xone_change = random.randrange (-20, 20)
yone_change = random.randrange (-20, 20)
poterbar_hunt_pone = False
ptwo_shot = False
poterbarx = -100
poterbary = -100
pygame.display.update() # You have to update display
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.