Question

I'm writing a game in python with pygame and need to render text onto the screen.

I want to render this text in one colour with an outline, so that I don't have to worry about what sort of background the the text is being displayed over.

pygame.font doesn't seem to offer support for doing this sort of thing directly, and I'm wondering if anyone has any good solutions for achieving this?

Was it helpful?

Solution

I can give you a quick and bad solution:

print the text 8 times, to surround it, plus one more time for the inner text, like this

UUU
UIU
UUU

U for outer color and I for the inner color.

OTHER TIPS

A quick and dirty way would be to render your text multiple times with the outline color, shifted by small amounts on a circle around the text position:

          1
       8  |  2
        \ | /
         \|/
     7----*----3
         /|\
        / | \ 
       6  |  4
          5

Edit: Doh you've been faster ! I wont delete my answer though, this ASCII art is just too good and deserves to live !

Edit 2: As OregonGhost mentioned, you may need more or fewer steps for the outline rendering, depending on your outline width.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top