[解決]蟒蛇pygame的int對象錯誤
蟒蛇扔我一個一個類型的錯誤,當我嘗試運行我的pygame的劇本,我找不到任何解決方案.. 我已經看了看周圍的其他職位,但couldn解決方案找不到任何幫助。我在哪裏錯了? 錯誤;
Traceback (most recent call last):
File "pygameclass.py", line 43, in <module>
ball.append(Ball(25, 400, 300 (50,50,50), "L", 25, 1, 100))
TypeError: 'int' object is not callable
我的代碼;
import pygame, sys, random
from pygame.locals import *
w = 800
h = 400
z = 0
screen = pygame.display.set_mode((w,h))
pygame.display.update()
class Ball:
def __init__(self, radius, y,x , color, size, maxforce, force, life):
self.y = y
self.x = x
self.size =size
self.maxforce = maxforce
self.force = force
self.radius = radius
self.color = color
self.life = life
pygame.draw.circle(screen, self.color, (self.x, self.y), self.radius)
def fall (self):
if self.y < h-self.radius:
self.y +=self.force
if self.force < self.maxforce:
self.force+=1
elif self.y > h-self.radius or self.y == h-self.raidus:
self.y = h-self.radius -1
self.force = self.force*-1
self.maxforce = self.maxforce/2
pygame.draw.circle(screen, self.color, (self.x, self.y), self.radius)
self.life-=1
if self.life<0:
ball.remove(self)
clock=pygame.time.Clock()
ball = []
ball.append(Ball(25, 400, 300 (50,50,50), "L", 25, 1, 100))
while True:
clock.tick(60)
x,y = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill((0,0,0))
for i in ball:
i.fall
你有沒有考慮過這樣做的生活?你已經救了自己很多的挫折,儘管儘管這些修復,球似乎不幹,我只剩下一個黑屏.. – 2014-10-18 20:57:49
不知道爲什麼,但你有另一個問題'ball.remove(self) '在那個秋天的方法,沒有球 – 2014-10-18 21:02:57
這可能是問題,爲什麼我留下了一個空白的屏幕,對不起,你已經篩選過的爛攤子,這是我第一天學習使用pygame – 2014-10-18 21:10:41