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

Re: [pygame] font/text in pygame



Denise-
Hey, the code you sent to me didn't work on my computer because I
don't have the livewires module.  I will send a copy of hiscore code I
make and if you like it feel free to use it, otherwise good luck
working it out!
-Luke
P.S. I understand it's urgent so I should be sending the code sometime tonight.


On 4/26/05, D. Hartley <denise.hartley@xxxxxxxxx> wrote:
> James,
> 
> 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?
> 
> Thank you!
> 
> ~Denise
> 
> On 4/26/05, James Reeves <jreeves@xxxxxxxxxxxxxxxxxxx> wrote:
> > On Wednesday 27 Apr 2005 12:26 am, D. Hartley wrote:
> > > What I am trying to find out is how (if possible) to get my text high
> > > score list (a list of tuples with names and scores) to something I can
> > > render on the game screen. I have images that are constant, which are
> > > rendered as pre-made gifs (or whatever), such as a fixed "Game Over"
> > > message, and so on.  But I cannot figure out how to get a dynamically
> > > changing object like my high score list to be rendered onto the game
> > > screen.
> >
> > It's a bit tricky to wrap your head around it at first, so I'll give you some
> > examples:
> >
> > # create a font object with the default typeface and 36 pixels (or is it
> > # points) tall.
> > font = pygame.font.Font(None, 36)
> >
> > # create a new surface with white, anti-aliased text on it:
> > text = font.render("Hello world", 1, (255, 255, 255, 0))
> >
> > # the 'text' object is just a surface with text on. You could get exactly the
> > # same result by creating an image with text on in your favourite graphics
> > # software, and then using pygame.image.load. The difference is, this text is
> > # created on the fly
> >
> > # blit the text surface to the screen
> > screen.blit(text, (0, 0))
> >
> > So to make a high score list, you'd need something like:
> >
> > x, y = 0, 0
> > for (name, score) in highscore_list:
> >        text = font.render("%s - %d" % (name, score), 1, (255, 255, 255, 0))
> >        screen.blit(text, (x, y))
> >        y += text.get_height()
> >
> > Notice that I increase the y by the height of the text each time, putting each
> > name and score on a new line.
> >
> > --
> > James Reeves
> > http://www.monkeyengines.co.uk/
> >
>