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

[pygame] NEWBIE: problem w/ sprites on 2 surfaces



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.

For each line in the message, I've created a different
sprite, with all the sprites (lineoftext) being on
their own surface (roll_surf). The title is NOT a
sprite, as I don't want it to move, and its blitted
onto the window. 

The problem I have is that when I run the program, the
lower half of the title text is blitted under the text
every time the text lines move down a few pixels. Just
try running it and I think you'll have a better
understanding of what I mean. I don't really
understand pygame that well and would appreciate any
help you can provide. A copy of my program is below:

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     

    def update ( self ):
        self.rect.move_ip ( 0, 1 )

screen = pygame.display.set_mode ( ( 640, 480 ) )

bg = pygame.Surface ( ( 640, 480 ) )
#screen.blit ( bg, ( 0, 0 ) )

title_size = 36

title_font = pygame.font.Font ( None, title_size )
title_rendered = title_font.render ( 'title', 1, (
255, 0, 0 ) )
screen.blit ( title_rendered, ( 20, 5 ) )

roll_surf = pygame.Surface ( ( 640, 480 ) )

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 ()

while 1:
    for event in pygame.event.get():
        if event.type == QUIT:
            break 

    screen.blit ( bg, ( 0, 100 ) )
    bg.blit ( roll_surf, ( 0, title_size + 200 ) )
    pygame.display.flip ()
    
    all.clear ( roll_surf, screen ) # clear the roll
surface

    all.update ()
            
    d = all.draw ( roll_surf ) # render all sprites
(ie Text Lines) onto roll_surface
    pygame.display.update ( d )
    
    
    time.sleep ( 1/5.0 )

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com