I am creating a class which shall return me a surface with a square and the text as displayed below:
The square (currently) shows the user's colour for the game and text is player name. I'll blit
these surfaces on the screen after calculating the positions from an array of similar surfaces.
I'm able to generate the text
surface easily. I don't want to pass the screen surface to the class for pygame.draw.rect
; but rather, create the rectangle separately; merge the rectangle and text surface and then return this grouped surface. My current class definition is simply:
from pygame.locals import *
from pygame import font as pyfont, event as pyevent, display as pydisplay
from sys import exit
class Info:
GRAY = ( 214, 171, 127 )
def __init__( self, name, colour ):
pyfont.init()
self.name = name
self.colour = colour
self.font = pyfont.Font( None, 36 )
def generate( self ):
text = self.font.render( self.name, True, self.GRAY )
# The rectangle surface to be drawn here
return text