colliderect()函数不会返回True和False;相反,它正在返回0和1。当我使用函数类型时,它说int而不是bool. 如果我使用0and1而不是布尔值进行编码,则代码有效,但为什么会发生这种情况?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
Run Code Online (Sandbox Code Playgroud)