Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
label transparency
#1
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
[Image: BKlNU.png]

---------
Reply
#2
Nice contribution, I dont do GUI's or games but I will keep this in mind of I ever do.
Reply
#3
Looks pretty cool.

Im guessing this is a label game?
Reply
#4
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.
Reply
#5
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)