11-18-2011, 07:38 AM
Just coding ago 1hours
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
---------