loading images as sprites in pygame

Solutions on MaxInterview for loading images as sprites in pygame by the best coders in the world

showing results for - "loading images as sprites in pygame"
Doug
19 Jul 2019
1class Player(pg.sprite.Sprite):
2
3    def __init__(self, pos, image):
4        super().__init__()
5        self.image = image
6        self.rect = self.image.get_rect(center=pos)
7
8
9player1 = Player((100, 300), IMAGE1)
10player2 = Player((300, 300), IMAGE2)
Norah
15 Aug 2016
1import pygame as pg
2
3
4pg.init()
5# The screen/display has to be initialized before you can load an image.
6screen = pg.display.set_mode((640, 480))
7
8IMAGE = pg.image.load('an_image.png').convert_alpha()
9
10
11class Player(pg.sprite.Sprite):
12
13    def __init__(self, pos):
14        super().__init__()
15        self.image = IMAGE
16        self.rect = self.image.get_rect(center=pos)