0

我正在为扑动的鸟制作克隆,但是当我想让翅膀拍动时,它们会疯狂地快速拍动,所以有没有办法让它们在一张图像上暂停几秒钟,然后再切换到下一张?这是我的代码

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)])`
4

1 回答 1

2

您应该首先设置帧速率限制,如下所示:

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

然后在主循环的最后放置:

fpsClock.tick(FPS)

此外,您不需要在每个条件语句中调用 pygame.displayupdate(),如果您将限制设置为 60,您知道游戏循环每秒执行 60 次,因此它的速度足以更新您的所有内容环形。

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

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

于 2014-02-21T18:28:04.657 回答