Код:
import pygame
import os
width = 800
height = 650
fps = 60
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
gamepapka = os.path.dirname(__file__)
kartinka = os.path.join(gamepapka,'img')
sprite_foto = pygame.image.load(os.path.join(kartinka,'pusheen-cat-pixel-art-image-vector-graphics-pusheen-drawings.jpg')).convert()
class sprite(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = sprite_foto
self.image.fill(GREEN)
self.rect = self.image.get_rect()
self.rect.center = (width / 2,height / 2)
pygame.init()
ekran = pygame.display.set_mode((width,height))
pygame.display.set_caption('Game')
clock = pygame.time.Clock()
selfsprite = pygame.sprite.Group()
imgg = sprite()
selfsprite.add(imgg)
run = True
while run:
clock.tick(fps)
for x in pygame.event.get():
if x.type == pygame.quit():
run = False
selfsprite.update()
selfsprite.draw(ekran)
pygame.display.flip()
pygame.quit()
Ошибка:
sprite_foto = pygame.image.load(os.path.join(kartinka,'pusheen-cat-pixel-art-image-vector-graphics-pusheen-drawings.jpg')).convert()
FileNotFoundError: No such file or directory.
Если указать полный путь:
r'C:\Users\user\Desktop\pusheen-cat-pixel-art-image-vector-graphics-pusheen-drawings.jpg'
:
File "C:\Users\user\PycharmProjects\Cat&Milk\Cat&Milk.py", line 11, in <module>
sprite_foto = pygame.image.load(os.path.join(kartinka,r'C:\Users\lolo\Desktop\pusheen-cat-pixel-art-image-vector-graphics-pusheen-drawings.jpg')).convert()
pygame.error: cannot convert without pygame.display initialized
Необходимо исправить ошибку и запустить pygame с спрайтом с картинкой