[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] font/text in pygame



On 4/27/05, D. Hartley <denise.hartley@xxxxxxxxx> wrote:
> I cannot thank you enough.  That was exactly what I needed.  I now
> have a working sample (just a box with a displayed high score list,
> not in my program yet but at least it's working!) - and it was in
> language I could actually understand.  My only question remains
> regarding the "x"  - it sets where the string begins (the left side of
> it), and since I have a series of strings of different lengths, I'd
> like to center them - how can i do this within the framework you
> provided?

James already gave you one way to center the text, but you can also
use the Rect objects in pygame for easy placement of surfaces. Using
James' code as a starting point:

x, y = 100, 0
for (name, score) in highscore_list:
       text = font.render("%s - %d" % (name, score), 1, (255, 255, 255, 0))
       r = text.get_rect()  # rectangle representing the surface area
       r.centerx = x   # set the center of the rectangle to a fixed point
       r.top = y
       screen.blit(text, r)   # rect can be passed directly to the blit function
       y += r.height

-- 
Sami Hangaslammi