【发布时间】:2015-03-09 14:21:09
【问题描述】:
我不断收到这种类型错误 TypeError:detectCollisions() 正好接受 8 个参数(给定 9 个)
def detectCollisions(x1,y1,w1,h1,x2,y2,w2,h2,):
if (x2+w2>=x1>=x2 and y2+h2>=y1>=y2):
return True
elif (x2+w2>=x1+w1>=x2 and y2+h2>=y1>=y2):
return True
elif (x2+w2>=x1>=x2 and y2+h2>=y1+h1>=y2):
return True
elif (x2+w2>=x1+w1>=x2 and y2+h2>=y1+h1>=y2):
return True
else:
return False
def update(self,gravity,blocklist):
if(self.velocity<0):
self.falling=True
blockX,blockY=0,0
collision=False
for block in blocklist:
collision = self.detectCollisions(self.x, self.y, self.width, self.height, block.x, block.y, block.width, block.height)
我不确定它有什么问题,我已经添加了一个 def 来检测碰撞
【问题讨论】:
-
旁白:你为什么将自我属性传递给
self.detectCollisions()?detectCollisions()不应该隐式访问self.x、self.y等吗? -
是的,该方法似乎应该简单地采用
self, other。 -
你应该给我们看一些代码。还不够,你的
class呢? -
我添加了更多代码。
标签: python pygame collision-detection typeerror