I'm trying to create a pygame program to display text
messages, with a message title and then the message
body below, with the message body moving down the
screen.
Hi;
I think this does what you want:
# scroller1.py
import pygame
from pygame.locals import QUIT
import time
pygame.display.init()
pygame.font.init()
class LineOfText(pygame.sprite.Sprite):
def __init__(self, text_rendered, x, y, containers):
pygame.sprite.Sprite.__init__(self, containers)
self.image = text_rendered
self.rect = text_rendered.get_rect()
self.rect.y = y
self.rect.x = x
all = pygame.sprite.RenderUpdates()
x = 10
y = 0
for line in ['abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJLMNOPQRSTUVWXYZ']:
text_font = pygame.font.Font(None, 32)
text_rendered = text_font.render(line, 1, (255, 255, 255))
LineOfText(text_rendered, x, y, all)
y = y + 32
pygame.display.flip()
done = 0
while not done:
for event in pygame.event.get():
if event.type == QUIT:
done = 1
### I think this is the problem... screen has the title
### on it, so when you use it to "clear" the title will
### show up. Make sure the background used to clear is
### the same size as the foreground surface, and that
### they are lined up.
all.clear(screen, bg) # clear the roll surface
all.update()
d = all.draw(screen) # render all sprites (ie Text Lines) onto
roll_surface
pygame.display.update(d)
# scroller2.py
import pygame
from pygsear.Drawable import String, Stationary, Layer, Image
from pygsear import Util
from pygsear.Game import Game
from pygsear.locals import TRANSPARENT
msg = """This is a very long message
which can contain newlines
and will be word wrapped automatically if the line \
gets to be too long to stay on one line like this one..."""