A
A
Agrael313 Zashefrovano2021-10-23 13:08:21
Python
Agrael313 Zashefrovano, 2021-10-23 13:08:21

How to make sprites from sheet transparent?

Help make sprites transparent when moving
I have sprites in a list, I can't make sprites transparent

import pygame

pygame.init()
x = 50
y = 530
speed = 5
screen_width = 1200
screen_height = 600
clock = pygame.time.Clock()
screen = pygame.display.set_mode((screen_width, screen_height))
playerstop = pygame.image.load('images/playerstop.png')
playerleft = [(pygame.image.load('images/playerleft1.png')), (pygame.image.load('images/playerleft2.png')), (pygame.image.load('images/playerleft3.png'))]
playerright = [(pygame.image.load('images/playerright1.png')), (pygame.image.load('images/playerright2.png')), (pygame.image.load('images/playerright3.png'))]
bg = pygame.transform.smoothscale(pygame.image.load('images/background3.jpg'), (screen_width, screen_height))

class Player():
    def __init__(self, x, y, width, height):
        self.screen = screen
        self.back = bg
        self.cord = self.back.get_rect()
        self.cord.x = 0
        self.cord.y = 0
        self.x = x
        self.y = y
        self.screen = screen
        self.width = width
        self.height = height
        self.val = 4
        self.left = False
        self.right = False
        self.playerstop = playerstop
        self.playerstop.set_colorkey((255, 255, 255))
        self.playerstop = True
        self.animCount = 0

    def draw(self, screen):
        self.screen.blit(self.back, self.cord)
        if self.animCount + 1 >= 15:
            self.animCount = 0

        if not self.playerstop:
            if self.left:
                screen.blit(playerleft[self.animCount // 5], (self.x, self.y))
                self.animCount += 1
            elif self.right:
                screen.blit(playerright[self.animCount // 5], (self.x, self.y))
                self.animCount += 1
        else:
            screen.blit(playerstop, (self.x, self.y))

    def move(self):
        key = pygame.key.get_pressed()
        if key[pygame.K_d]:
            self.x += self.val
            self.left = False
            self.right = True
            self.playerstop = False
        elif key[pygame.K_a]:
            self.x -= self.val
            self.left = True
            self.right = False
            self.playerstop = False
        else:
            self.playerstop = True

man = Player(0, 530, 1200, 600)

run = True
while run:
    clock.tick(40)
    screen.fill((0, 0 ,0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    man.draw(screen)
    man.move()
    pygame.display.update()

Who is not difficult to write please
Thank you

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question