Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
class Insurance(pygame.sprite.Sprite):
    def __init__(self, pos):
        pygame.sprite.Sprite.__init__(self, self.containers)
        self.image = load_image2("insurance1.jpg")
        self._image = self.image
        self.rect = self.image.get_rect(topleft = pos)
        self._rect = Rect(self.rect)
        self.life = 255
        self.killed = False
    def kill(self):
        self.killed = True
    def update(self):
        if self.killed:
            self.life -= 15
            if self.life <= 0:
                pygame.sprite.Sprite.kill(self)
        self.image.set_alpha(self.life)


The above code is my class. When I edit my image in gimp it shows its transparent but when I run it in the game it shows up with white in the background. I have tried putting in different lines of code but cant get it to work. Any suggestions?
Posted
Comments
Sergey Alexandrovich Kryukov 20-Feb-12 10:19am    
Are you sure your "life" is small enough to observe transparency in your logic? Maybe your code works with "life" == 255? Anyway, start with simplest code testing that transparency is supported in principle.

Also, transparency with set_alpha and transparency with the image alpha channel (it looks like you used both) are different things. Check up it they are supported on two different examples. If they are both supported, check up you logic.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900