嗨,我正在尝试使用 pygame 制作一个简单的 2d 汽车游戏,并且正在尝试添加两辆车之间的碰撞,但我不断收到此错误:
Traceback (most recent call last):
File "C:\Users\emilio pinto\Desktop\Running car proj\Running car.py", line 69, in <module>
if pygame.Rect.collidelist(car1,car2) >= 0:
TypeError: Argument must be a sequence of rectstyle objects.
我很确定我一直很好地使用 .Rect 模块,无论如何,这些是变量以及我如何尝试使用它们:
car1=pygame.Rect((xCar, yCar), (60, 30))
car2=pygame.Rect((xCar2, yCar2), (60, 30))
if pygame.Rect.collidelist(car1,car2) >= 0:
running=False
screen.fill((0,0,0))
screen.blit(loseText, (142, 90))
screen.blit(loseText2,(110, 170))
pygame.display.flip()
if keys[pygame.K_SPACE]:
running=True
continue
最佳答案
这应该可以解决您的问题:
if pygame.Rect.colliderect(car1,car2) >= 0:
说明:
您使用了错误的函数,或者该函数的参数错误。
对两个对象使用Rect.colliderect
:
https://www.pygame.org/docs/ref/rect.html#pygame.Rect.colliderect
或者使用Rect.collidelist
作为对象列表。因此,您必须将 car1
和 car2
放入列表对象中。
https://www.pygame.org/docs/ref/rect.html#pygame.Rect.collidelist
关于python - 错误 pygame : Argument must be a sequence of rectstyle objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63881210/