标签: pygame2

如何修复此 DeprecationWarning

弃用警告:需要一个整数(得到类型浮点数)。int不推荐使用隐式转换为整数,并且可能会在 Python 的未来版本中删除。

win.blit(playerStand, (x, y))

弃用警告:需要一个整数(得到类型浮点数)。int不推荐使用隐式转换为整数,并且可能会在 Python 的未来版本中删除。

win.blit(walkLeft[animCount // 5], (x, y))

python pygame python-3.x pygame-surface pygame2

5
推荐指数
1
解决办法
1万
查看次数

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.init() 执行 40 秒?

Pygame 昨晚运行良好,现在 pygame.init() 函数与之前的瞬间相比需要大约 40 秒才能完成。

import pygame
import time
start = time.time()
pygame.init()
print(f"Runtime: {time.time() - start}")
Run Code Online (Sandbox Code Playgroud)

控制台结果:

"C:\Program Files\Python39\python.exe" "D:/Google Drive/CompSci/proj/Alien Invasion/test.py"
pygame 2.0.1 (SDL 2.0.14, Python 3.9.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
Runtime: 40.15961766242981
Run Code Online (Sandbox Code Playgroud)

通常运行时应该几乎是即时的......

我在 Windows Defender 中排除了所有相关文件夹: Windows Defender 排除项

python performance pygame pygame2

0
推荐指数
1
解决办法
58
查看次数