MODULE PYGAME
consolance
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
nuirose -
nuirose -
Bonjour,
J'ai un problème avec le code ci dessous
La classe player ne contient pas l'attribut img
J'ignore pourquoi
import pygame pygame.init() #create a class for the player class Player(pygame.sprite.Sprite): def __int__(self): super().__init__() self.health = 100 self.max_health = 100 self.attack = 10 self.velocity = 5 # movement self.img = pygame.image.load('assets/player.png') self.rect = self.img.get_rect() # move the image self.rect.x = 400 self.rect.y = 500 pygame.display.set_caption("Comet fall game") screen = pygame.display.set_mode((1080, 720)) #import the background background = pygame.image.load('assets/bg.jpg') # image = pygame.image.load('assets/player.png') #charge the player player = Player() running = True while running: # apply the background screen.blit(background, (0, -200)) # apply the image of the player screen.blit(player.img, player.rect) # upload the image pygame.display.flip() #if the player closes the window for event in pygame.event.get(): #To close the window if event.type == pygame.QUIT: running = False pygame.quit()
EDIT : Déplacement dans le bon forum*
EDIT²: Ajout du LANGAGE dans les balises de code
Windows / Chrome 111.0.0.0