Today’s function means to load images and in a future post we will add features to show it on the screen where you click with the mouse. If you click again on the image it disappeares. If you drag it it will move. I you use the wheel but it will increase or decrease size. Let’s go.
import pygame import sys pygame.init() # first Surface screen_size = screen_w, screen_h = 1000, 800 screen = pygame.display.set_mode((screen_size)) screen_centerw = screen_w//2 screen_centery = screen_h//2 screen_center = screen_w, screen_w clock = pygame.time.Clock() sprites = pygame.sprite.Group() class Image(pygame.sprite.Sprite): def __init__(self, path, x, y): super().__init__() self.path = path self.x = x self.y = y sprites.add(self) self.load() def load(self): self.image = pygame.image.load(self.path) self.rect = self.image.get_rect() self.rect.x = self.x self.rect.y = self.y time = 0 pl1 = Image("player\\Walk (1).png", 400, 100) pl2 = Image("player\\Jump (1).png", -100, 100) RUN = 1 while RUN: screen.fill(0) for event in pygame.event.get(): if event.type == pygame.QUIT: RUN = 0 # pygame.draw.rect(screen, (255,255,255), pl1rect) sprites.update() sprites.draw(screen) pygame.display.flip() time += 1 clock.tick(60) pygame.quit() sys.exit()
The video tutorial
Ok, I wish you liked it. See ya the on the 3rd of september.
Subscribe to the newsletter for updates
Tkinter templates
My youtube channel
Twitter: @pythonprogrammi - python_pygame