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

Re: [pygame] Font



Here's a text class I wrote that I use myself. It automatically creates the text, and caches it for you.

the files are:

text.py : does all the cache-ing, blit-ting, all the 'under the hood' stuff
test_text.py : a bunch of examples on using the text wrapper ( view this file first )
game.py : boilerplate code, don't need to read

== Usage: ==
in Game.init():
# create regular text, and FPS text
hi = Text('Hi world')
fps = FPSText()

in Game.draw(self):
# draw regular text
self.text.draw()

# draw FPS text, and update it
self.fps.draw()
self.fps.tick()

== Notes ==

Text() is 'smart', meaning it will only render the text if needed. the  method .draw() will use a cached version of the render.

Meaning: you can do this, and it only renders once: ( or none if it was already set to that. )

self.text.text="mwhahahaha"
self.text.text="mwhahahaha"
self.text.text="mwhahahaha"


On Tue, Mar 24, 2009 at 8:55 PM, Yanom Mobis <yanom@xxxxxxxxxxxxxx> wrote:
How do you use the font module exactly? I don't care about all the fancy stuff, I just want text in a specific color...




--
Jake

Attachment: pygame_text_example.zip
Description: Zip archive