Today I succeeded in making text appear on the screen!
There's actually an entire sub-module in PyGame for doing text, pygame.font.
Creating text is a simple case of first creating a font; like so:
newfont = pygame.font.Font(file, size)
"File" can simply be "None" if you want to use the default font (as I'm doing at the moment). This line creates a PyGame Font object, which can then be used to render text:
newfont.render("Your text here", antialias, colour, background)
"Antialias" is simply a boolean True or False, used to tell PyGame whether or not to antialias the text. "Colour" is the colour of the text, and "background" is the background colour - if you don't include this argument then the text will be rendered with a transparent background which, although useful under most circumstances, uses far more processing power than normal text. If you're writing a large game or one with a lot going on at once, it's probably a good idea only to use text with a transparent background when it's absolutely necessary.
Anyway, here are the results of my experiments with text.
Whilst twiddling with text modules, I also found a very interesting example of animated text, which moves in a recurring wavelike pattern. It seems to be doing it by moving individual columns of pixels up and down by certain amounts (defined through confusing use of the cosine function) every frame and displaying them on the screen individually. It's slightly confusing to say the least.
After this, I think the next thing to try is using sprites; these are special classes used for handling game objects and have extra functions and attributes for collision detection. I've found a tutorial on them and so shall post any progress when it's made.
No comments:
Post a Comment