Support Forums
label transparency - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: label transparency (/showthread.php?tid=23319)



label transparency - HF~Legend - 11-18-2011

Just coding ago 1hours Superman

Code:
""" this is the code that sets up a new label with custom settings """
self.title = gui.Label(self.scene)
self.title.font = pygame.font.SysFont(None, 30)
self.title.text = "Welcome Label Transparency by Legend"
self.title.foreground = ((0, 0, 0))
self.title.background = ((0,0,0,0))
self.title.center = (320, 50)

""" acutal code that sets up the label """

class Label(pygame.sprite.Sprite):
    def __init__(self, game):
        """ init the label and set it up has the font(what font it uses) the
            text(what the label says), and the fg and bg to change colors """
        self.game = game
        self.screen = game.screen
        pygame.sprite.Sprite.__init__(self)
        self.font = pygame.font.SysFont("None", 30)
        self.text = ""
        self.foreground = ((0, 0, 0))
        self.background = ((255, 255, 255))
        self.center = (100, 100)
        self.size = (150, 30)
    def update(self):
        self.image = pygame.Surface(self.size)
        self.image.fill(self.background)
        fontSurface = self.font.render(self.text, True, self.foreground, self.background)

        xPos = (self.image.get_width() - fontSurface.get_width()) / 2
        yPos = (self.image.get_height() - fontSurface.get_height()) / 2
        self.image.blit(fontSurface, (xPos, yPos))
        self.rect = self.image.get_rect()
        self.rect.center = self.center



RE: label transparency - Rhynorater - 12-17-2011

Nice contribution, I dont do GUI's or games but I will keep this in mind of I ever do.


RE: label transparency - Pikachu - 01-05-2012

Looks pretty cool.

Im guessing this is a label game?


RE: label transparency - Quizzical - 01-06-2012

I don't do much when it comes to this, but this is a pretty cool Python code. I'll check this out in the near future when I may need it to do something with logos. And wow this only took you an hour? Very good work man, you should release more in this section.


RE: label transparency - AceInfinity - 01-06-2012

Pretty basic here, you're using argb by defining an extra value for the color value parameters to interpret. If it's not inputted I believe it just defaults over to 255 which is FF (max) in hexadecimal.