弃用警告:需要一个整数(得到类型浮点数)。
int不推荐使用隐式转换为整数,并且可能会在 Python 的未来版本中删除。
win.blit(playerStand, (x, y))
弃用警告:需要一个整数(得到类型浮点数)。
int不推荐使用隐式转换为整数,并且可能会在 Python 的未来版本中删除。
win.blit(walkLeft[animCount // 5], (x, y))
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) 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 排除项