2012-04-26 178 views
1

我有這個問題,當我想去遊戲結束屏幕。TypeError:'pygame.Surface'對象不可調用

Traceback (most recent call last): 
    File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 215, in <module> 
    game() 
File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 191, in game 
    text("Game Over",30,white,300) 
TypeError: 'pygame.Surface' object is not callable 

這對於存在屏幕的代碼段:

while finish == True: 
screen.blit(menu,[0,0]) 
text("Game Over",30,white,300) 
text("Instructions",310,white) 
text("-----------------------------------------------------",320,white) 
text("Avoid the the enemies",340,white) 
text("Last as long as you can!",360,white) 
text("Press space to start",420,white) 

# display.update() 
pygame.display.update() 

for event in pygame.event.get(): 
if event.type == pygame.QUIT: 
    repeat = False 

if event.type == pygame.KEYDOWN: 
    if event.key == pygame.K_SPACE: 
    repeat = True 

if repeat == False: 
pygame.quit() 

else: 
game() 

game() 

如果我刪除遊戲中的文字在屏幕上,它的工作。我只要我介紹的文字,我得到上面的錯誤消息

(縮進是不正確的),我有充分的代碼在這裏茚http://pastebin.com/VBkhX4kt

謝謝

回答

1

這個錯誤是因爲在線93你覆蓋變量text從函數到任何font.render()返回的綁定。

93: text = font.render('Starting Twerk... ', True, (100,100,100)) 

因此,後來,當你調用text(...)它不給你打電話之前定義的函數,它試圖把text的調用(它不是,因爲它現在是一個pygame.Surface對象)。

解決方法是更改​​該行,而不是覆蓋您的text函數。

+0

謝謝,這是問題所在。 – ErHunt 2012-04-26 01:48:01