如何在pygame中使玩家图像暂停,但游戏仍然继续?

2024-09-28 22:32:20 发布

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

我正在为flappy bird做一个克隆,但是当我想让翅膀拍打时,它们会疯狂地快速拍打,所以有没有办法让它们在换下一张之前在一张图片上停顿几秒钟?这是我的密码

first=1
if first==1:
    playern=1
    comeback=False
    first=2
if obspeed==1 and playern==1:
    imagefile="player1"
    player=pygame.image.load(imagefile+".png")
    screen.blit(player, [x, int(y)])
    y+=3
    playern=2
    pygame.display.update()
if obspeed==1 and playern==2 and comeback==False:
    imagefile="player"
    player=pygame.image.load(imagefile+".png")
    screen.blit(player, [x, int(y)])
    y-=2
    playern=3
    pygame.display.update()
if obspeed==1 and playern==3:
    imagefile="player3"
    player=pygame.image.load(imagefile+".png")
    screen.blit(player, [x, int(y)])
    y-=3
    playern=2
    comeback=True
    pygame.display.update()
if obspeed==1 and playern==2 and comeback==True:
    imagefile="player"
    player=pygame.image.load(imagefile+".png")
    screen.blit(player, [x, int(y)])
    y+=2
    playern=1
    comeback=False
    pygame.display.update()
if obspeed==0:
    imagefile="player2"
    player=pygame.image.load(imagefile+".png")
    screen.blit(player, [x, int(y)])`

Tags: andimageifpngdisplayloadscreenpygame
1条回答
网友
1楼 · 发布于 2024-09-28 22:32:20

您应该这样设置帧速率限制:

FPS = 60
fpsClock = pygame.time.Clock()

然后在主循环的最后,输入:

fpsClock.tick(FPS)

你也不需要打电话pygame.displayupdate文件()在每个条件语句中,您知道游戏循环每秒执行60次,如果您将限制设置为60,那么它的速度足以更新循环中发生的所有事情。你知道吗

我建议您阅读以下内容: http://inventwithpython.com/pygame/chapters/

那本在线书很好地解释了如何使用pygame 我希望这能帮助你:)

相关问题 更多 >