How do I assign Images to Sprites with pygame
Question:
I am struggling to give each sprite their own image in the code below and i cant seem to find a way to do it, if anyone could help it would be much appreciated. Thanks. (This is my first time using stack overflow so aplogies if the formating is messy or wrong) Also let me know if i should put in the text map file.
version/tree/main
Answers:
In your child class for each sprite you want an image, you need to add a variable that holds the loaded image you want to display. Then, when you display that sprite, you just use that particular variable from the class.
class PlatBasic(Entity):
def __init__(self, pos, *groups):
self.image = pygame.image.load("PlatBasic.png").convert()
super().__init__(Color("#10eb93"), pos, *groups)
Then when you wish to display it, you can just do:
x = PlatBasic((0,0))
screen.blit(x.image,x.pos)
I am struggling to give each sprite their own image in the code below and i cant seem to find a way to do it, if anyone could help it would be much appreciated. Thanks. (This is my first time using stack overflow so aplogies if the formating is messy or wrong) Also let me know if i should put in the text map file.
version/tree/main
In your child class for each sprite you want an image, you need to add a variable that holds the loaded image you want to display. Then, when you display that sprite, you just use that particular variable from the class.
class PlatBasic(Entity):
def __init__(self, pos, *groups):
self.image = pygame.image.load("PlatBasic.png").convert()
super().__init__(Color("#10eb93"), pos, *groups)
Then when you wish to display it, you can just do:
x = PlatBasic((0,0))
screen.blit(x.image,x.pos)