[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Fwd: [pygame] font/text in pygame
Sami,
I tried that code and it's telling me:
text_score = font.render("%d" % (score), 1, (255, 255, 255, 0))
TypeError: int argument required
But why would it be requiring an int? font.render has to take a string...?
---------- Forwarded message ----------
From: Sami Hangaslammi <sami.hangaslammi@xxxxxxxxx>
Date: Apr 27, 2005 11:29 PM
Subject: Re: [pygame] font/text in pygame
To: pygame-users@xxxxxxxx
On 4/28/05, D. Hartley <denise.hartley@xxxxxxxxx> wrote:
> One last font question:
>
> My code for lining up the two columns (score and name, both
> left-aligned), worked in the sample program:
>
> slip = 30 - len(name)
> slip_amt = slip*" "
>
> But it's not lining them up on my screen now?
You can't use spaces to align true-type fonts, as different letters
have different widths. The easiest way is probably to font.render the
name and score into separate surfaces and blit them separately. Using
the previous example code (not tested):
y = 100
for (name, score) in highscore_list:
text_name = font.render(name, 1, (255, 255, 255, 0))
text_score = font.render("%d" % score, 1, (255, 255, 255, 0))
rect_name = text_name.get_rect()
rect_score = text_score.get_rect()
rect_name.left = 100 # x position for name column
rect_score.left = 200 # x position for score column
rect_name.top = y
rect_score.top = y
screen.blit(text_name, rect_name)
screen.blit(text_score, rect_score)
y += r.height
--
Sami Hangaslammi