I need my sprite to appear in the pygame window. How do I do this? Important code:
#This will be a list that will contain all the sprites we intend to use in our game.
all_sprites_list = pygame.sprite.Group()
#creating the player
player = player(BLUE, 60, 80, 70)
player.rect.x = 200
player.rect.y = 300
At the end of the code I have pygame.display.update()
. My sprite class (correctly imported):
class player(pygame.sprite.Sprite):
def __init__(self, color, width, height, speed):
# Call the parent class (Sprite) constructor
super().__init__()
# Pass in the color of the player, and its x and y position, width and height.
# Set the background color and set it to be transparent
self.image = pygame.Surface([width, height])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
#Initialise attributes of the car.
self.width = width
self.height = height
self.color = color
self.speed = speed
# Draw the player
pygame.draw.circle(self.image, self.color, (400, 600), 5)
self.rect = self.image.get_rect()
Could be a stupid human mistake. I tried replacing self.rect = self.image.get_rect()
with self.rect = self.image.get_circle()
as my sprite is circular but this returns:
self.rect = self.image.get_circle()
AttributeError: 'pygame.Surface' object has no attribute 'get_circle'
Can I have some help please?