I'm making a function that takes a string a breaks it up into lines and returns a surface with each line rendered below the previous one.
For example:
Line1
Line 2
Renders into:
Line1
Line2
Anyway, my problem is that I cannot return a properly transparent surface to the calling function. I've tried using a color-key, but it does't work with anti-aliased text. Is there a way I can do this? Thanks for your answers.
My code: (Currently leaves an ugly purple shadow around text)
def render_message(messages):
surfaces = []
height = 0
max_width = 0
for message in messages.split('
'):
surf = FONT.render(message, True, (0, 0, 0))
surfaces.append(surf)
height += surf.get_height() + 5
if surf.get_width() > max_width:
max_width = surf.get_width()
result = pygame.Surface((max_width, height))
result.fill((255, 0, 255))
result.set_colorkey((255, 0, 255))
top = 0
for surface in surfaces:
result.blit(surface, (max_width/2-surface.get_width()/2, top))
top += surface.get_height() + 5
return result
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…