0
votes

Im relative new to pygame. Im having a bit of a trouble here. I have searched for documentations but cant figure out why i get this error.

AttributeError: 'Knight' object has no attribute 'rect'

class Knight(pg.sprite.Sprite):

    def __init__(self, x, y):
        pg.sprite.Sprite.__init__(self)

        self.image = pg.image.load("image\\knight.png").convert()

        self.rect = self.rect.get_rect()
        self.rect.x = x
        self.rect.y = y

Here is where i call the class.

allSprites = pg.sprite.Group()
player = Knight(0, 0)
allSprites.add(player)

run = True
while run:


    for event in pg.event.get():

        if event.type == pg.QUIT:
            run = False

        keys = pg.key.get_pressed()


    """ Updating all sprites and the window """
    allSprites.update()
    allSprites.draw()

My question is why does pygame thinks my class is an object instead of a sprite class?

1

1 Answers

1
votes

Erik77, I don't know pygame, but are you sure this is correct?

self.rect = self.rect.get_rect()

Have the Sprite class the property "react"?