小编Cés*_*ado的帖子

Pygame colliderect() 函数返回 0(零)和 1(一个)而不是 True 和 False?

colliderect()函数不会返回TrueFalse;相反,它正在返回01。当我使用函数类型时,它说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)

python pygame python-3.x pygame2

4
推荐指数
1
解决办法
73
查看次数

标签 统计

pygame ×1

pygame2 ×1

python ×1

python-3.x ×1