pygame中的图像移动(崩溃pygame)

2024-09-29 17:11:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个游戏,当这个循环运行时,它会崩溃

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崩溃了,我想是在波特的运动中。 如果你们中有人知道是什么导致pygame崩溃请告诉我


Tags: andtrueifdirwidthhuntshotxone
1条回答
网友
1楼 · 发布于 2024-09-29 17:11:39

您缺少pygame.display.update()。你知道吗

将此添加到代码的最底部,使其看起来像:

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

相关问题 更多 >

    热门问题