pygame图像碰撞检测

时间:2019-08-23 18:02:46

标签: python python-3.x pygame collision-detection

我的游戏的碰撞不起作用

我总是会说一个错误:

Traceback (most recent call last):
  File "C:\Yaseen's Needed Stuff\Python Projects\pyweek-dojo-master\resource\image\player_1\kgame2.py", line 52, in <module>
    hit()
  File "C:\Yaseen's Needed Stuff\Python Projects\pyweek-dojo-master\resource\image\player_1\kgame2.py", line 42, in hit
    if pygame.sprite.spritecollide(sprite,enemy, False):
  File "C:\Users\yasee\AppData\Roaming\Python\Python37\site-packages\pygame\sprite.py", line 1534, in spritecollide
    spritecollide = sprite.rect.colliderect
AttributeError: 'pygame.Surface' object has no attribute 'rect'

这是碰撞代码

if pygame.sprite.spritecollide(spriterect, enemyrect, False):
    lives = lives - 1

这是图片

enemy = pygame.image.load('player_2_0.png') 
sprite = pygame.image.load('player_1_0.png')

我该怎么办?

0 个答案:

没有答案