AttributeError:' pygame.Rect'对象没有属性' rect'

时间:2014-04-21 07:18:13

标签: python python-3.x pygame

我想在一个类中创建一个碰撞模块,但是当我用两个精灵来调用它时,这个精灵有一个用它们定义的矩形。这是包含它的代码

致电模块:

elif playerCol.checkCollision(playerrect, waterrect):
    if True:
        print('True')

课程和单元:

class collision():
    def checkCollision(self, sprite1, sprite2):
        col = pygame.sprite.collide_rect(sprite1, sprite2)
        if col == True:
            return True

精灵:

player = pygame.image.load("Textures(Final)\player.bmp").convert()
playerrect = player.get_rect()
player.set_colorkey(WHITE)

grasstile = pygame.image.load("Textures(Final)\Grass_Tile.bmp").convert()
watertile = pygame.image.load("Textures(Final)\Water_Tile.bmp").convert()
waterbeach = pygame.image.load("Textures(Final)\Water_Beach.bmp").convert()
grassrect = grasstile.get_rect()
waterrect = watertile.get_rect()
waterb = waterbeach.get_rect()

完整错误是:

Traceback (most recent call last):
  File "F:\Desktop Files\Python\Pygame RPG Type Game\RPG TEST 2.py", line 153, in <module>
    main()
  File "F:\Desktop Files\Python\Pygame RPG Type Game\RPG TEST 2.py", line 102, in main
    elif playerCol.checkCollision(playerrect, waterrect):
  File "F:\Desktop Files\Python\Pygame RPG Type Game\RPG TEST 2.py", line 147, in checkCollision
    col = pygame.sprite.collide_rect(sprite1, sprite2)
  File "F:\Python33\lib\site-packages\pygame\sprite.py", line 1300, in collide_rect
    return left.rect.colliderect(right.rect)
AttributeError: 'pygame.Rect' object has no attribute 'rect'

我希望这是帮助我识别问题所需的所有代码。我花了3个小时来解决这个问题,遗憾的是我找不到自己的解决方案。谢谢你的帮助!

0 个答案:

没有答案