簡體   English   中英

如何使玩家圖像暫停,但游戲繼續在pygame?

[英]How to make player image pause but game continues in pygame?

我正在為一只脆弱的鳥做一個克隆,但是當我想要翅膀拍打時,它們會迅速地快速拍打,所以有沒有辦法讓它們暫停在一張圖片上幾秒鍾之后再轉換到下一張圖片? 繼承我的代碼

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

您應該首先設置幀速率限制,如下所示:

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

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

fpsClock.tick(FPS)

你也不需要在每個條件語句中調用pygame.displayupdate(),你知道游戲循環每秒執行60次,如果你將限制設置為60,那么它的速度足夠快,可以更新你的所有內容。環。

我建議你閱讀這篇文章: http//inventwithpython.com/pygame/chapters/

那本在線書籍很好地解釋了如何使用pygame我希望這可以幫助你:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM