Python pygame writing text in sprite -


i making game shall shoot down diffrent boxes diffrent nummber , text on , wondring if can write text sprite

first off feel haven't done research, song free code. answer question, don't think ever again.

class text(pygame.sprite.sprite):     def __init__(self, text, size, color, width, height):         # call parent class (sprite) constructor           pygame.sprite.sprite.__init__(self)          self.font = pygame.font.sysfont("arial", size)         self.textsurf = self.font.render(text, 1, color)         self.surf = pygame.surface((width, height))         w = self.textsurf.get_width()         h = self.textsurf.get_height()         self.surf.blit(self.textsurf, width/2 - w/2, height/2 - h/2) 

i hope helps, draw text centered on surface in sprite


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -