有誰知道我怎樣才能讓分數顯示在我的遊戲畫面上?印刷分數 - Pygame
到目前爲止,我有這樣的代碼:
for bullet in bullet_list:
block_hit_list = pygame.sprite.spritecollide(bullet, block_list, True)
for block in block_hit_list:
explosion.play()
bullet_list.remove(bullet)
all_sprites_list.remove(bullet)
score += 10
font = pygame.font.Font(None, 36)
text = font.render(score, 1, (WHITE))
textpos = text.get_rect(centerx=background.get_width()/2)
background.blit(text, textpos)
if bullet.rect.y < -10:
bullet_list.remove(bullet)
all_sprites_list.remove(bullet)
不過,我收到此錯誤當我運行遊戲和射擊子彈:
「文本= font.render(得分,1,( WHITE))
類型錯誤:文本必須是Unicode或字節」
有誰知道如何解決這個問題呢?
謝謝
感謝您的回覆,這款作品完美無瑕,但我仍然存在一個問題,分數連續顯示在彼此之上?在顯示20之前清除分數,而不是顯示10,然後在20等之上顯示10,從而給我留下難以辨認的文字 – Oscar
@Oscar你可以發佈當前的代碼,最好多一點主循環嗎? – KodyVanRy
當然,我把它放在Pastebin上:http://pastebin.com/gLMXz4W6 – Oscar