1

ゲームオーバー画面に行きたいときにこの問題が発生します。

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

ありがとうございました

4

1 に答える 1

1

エラーは、93 行text目で関数から font.render() が返すものへの変数のバインドをオーバーライドしているためです。

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

したがって、後で呼び出すtext(...)と、以前に定義した関数を呼び出すのではなく、呼び出し可能として処理しようとしますtext(現在は pygame.Surface オブジェクトであるため、そうではありません)。

text解決策は、その行を変更し、関数をオーバーライドしないことです。

于 2012-04-26T01:09:04.130 に答える