2015-01-08 31 views
0

我正在與pygame的遊戲,我試圖打印變量「錢」,但每當我嘗試遊戲給我這個錯誤:pygame的,font.render錯誤

Traceback (most recent call last): 
    File "C:\Users\camil\Desktop\final\New.py", line 201, in <module> 
    scoretext=font.render(money, 'coins', 1,(0,0,1)) 
TypeError: an integer is required 

這是我的代碼,我有不知道什麼問題是如此的幫助將不勝感激:

while True: 
    global money 

    plot = plot+1 

    setDisplay.fill((255,255,255)) 

    font=pygame.font.Font(None,20) 
    scoretext=font.render(money, 'coins', 1,(0,0,0)) 
    setDisplay.blit(scoretext, (1130, 5)) 

回答

0

我假設你正在試圖呈現某人有的硬幣的數量 - 例如「十個硬幣」?

既然如此,你正在過「10」和「硬幣」作爲獨立變量,需要將它們傳遞給函數之前,將它們組合成一個單一的對象:

font.render('%d coins' % (money,), 1,(0,0,0)) 

確保你仔細看一下所需參數的文件中:

http://www.pygame.org/docs/ref/font.html#pygame.font.Font.render

0

的函數原型Font.render()看起來像這樣

Font.render(text, antialias, color, background=None): return Surface 

您沒有將正確的參數傳遞給函數,錯誤消息告訴你什麼(需要整數)。我假設你想顯示'XXX硬幣',試試這個:

Font.render(money + ' coins', 0, 1, (0,0,0))