How can I make it so set_colorkey makes all of the colored pixels transparent?

Viewed 23

I used set_colorkey((255,255,255)) on my sprites but it doesn't make all the white transparent. I already tried doing .convert() but it is still the same. This is how it looks: image1 This is the code where I try to make the color transparent:

class Snake:
    def __init__(self, parent_screen):
        self.parent_screen = parent_screen
        self.stationary = pygame.image.load('/Users/gersh/PycharmProjects/snakeeo/venv/lib/resources/ash trainer sprites/stationary down.png')

        self.left = pygame.image.load('/Users/gersh/PycharmProjects/snakeeo/venv/lib/resources/ash trainer sprites/cycle left.png')


        self.right = pygame.image.load('/Users/gersh/PycharmProjects/snakeeo/venv/lib/resources/ash trainer sprites/cycle right.png')


        self.up = [pygame.image.load('/Users/gersh/PycharmProjects/snakeeo/venv/lib/resources/ash trainer sprites/left leg up.png'),
                   pygame.image.load('/Users/gersh/PycharmProjects/snakeeo/venv/lib/resources/ash trainer sprites/right leg up.png')]

        self.down =[pygame.image.load('/Users/gersh/PycharmProjects/snakeeo/venv/lib/resources/ash trainer sprites/right leg down.png'),
                    pygame.image.load('/Users/gersh/PycharmProjects/snakeeo/venv/lib/resources/ash trainer sprites/left leg down.png')]
        self.x = 100
        self.y = 100
        self.direction = 'down'

    def draw(self):
        global stepIndex
        self.parent_screen.fill((0, 0, 0))
        if stepIndex >= 2:
            stepIndex = 0
        if self.direction == 'left':
            self.left.set_colorkey((255, 255, 255))
            self.parent_screen.blit(self.left, (self.x, self.y))

        elif self.direction == 'right':
            self.right.set_colorkey((255, 255, 255))
            self.parent_screen.blit(self.right, (self.x, self.y))

        elif self.direction == 'up':
            self.up[0].set_colorkey((255, 255, 255))
            self.up[1].set_colorkey((255, 255, 255))
            self.parent_screen.blit(self.up[stepIndex], (self.x, self.y))
            stepIndex += 1
        elif self.direction == 'down':
            self.down[0].set_colorkey((255, 255, 255))
            self.down[1].set_colorkey((255, 255, 255))
            self.parent_screen.blit(self.down[stepIndex], (self.x, self.y))
            stepIndex += 1
        pygame.display.flip()
        pygame.time.delay(30)
0 Answers
Related