Hi I've got a problem with Sprite class. I defined self.image and self.rect in my class init function and still getting an error: AttributeError: 'Sprite' object has no attribute 'rect'
I've read couple of topics related to this problem and always somebody was missing these attribiutes. I have no clue how to resolve this problem. In line
player.draw(screen)
I am getting an error: AttributeError: 'Player' object has no attribute 'image'
import pygame
class Player(pygame.sprite.Sprite):
def __int__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('graphics/player/p1_walk01.png')
self.rect = self.image.get_rect(midbottom=(200, 330))
pygame.init()
screen = pygame.display.set_mode((800, 400))
pygame.display.set_caption('Game')
clock = pygame.time.Clock()
# Backgrounds
sky_surf = pygame.image.load('graphics/background/bg.png').convert()
ground_surf = pygame.image.load('graphics/background/ground.png').convert()
player_obj = Player()
player = pygame.sprite.GroupSingle()
player.add(player_obj)
while True:
screen.blit(sky_surf, (0, 0))
screen.blit(ground_surf, (0, 330))
player.draw(screen)
pygame.display.update()
clock.tick(60)