colliderect()
函数不会返回True
和False
;相反,它正在返回0
and 1
。当我使用它说的函数类型int
而不是bool
. 如果我使用0
and1
而不是布尔值进行编码,则代码可以工作,但为什么会发生这种情况?Pygame 文档没有提到任何关于它的内容。
def collisions():
tileHitsList = []
for rect in tileList:
print(testcube.colliderect(rect)) #it weirdly prints 0 and 1 instead of False and True
#tileList is a list which contains the rects of the tiles being rendering on the display
#testcube is a rect that hits the tiles
if testcube.colliderect(rect) == True:
tileHitsList.append(rect)
return tileHitsList