
-----------------------------------
Notthebbq
Tue Apr 12, 2011 11:59 am

Moving Text across a background
-----------------------------------
Hello there, our team has another question. We have managed to import text onto a background using a snippet code from a site, but how do we move the text around? This is a copy pasta of what we have found. Thank you. With this code, we are only able to put the text in the center, and to be honest we haven't modified the code snippet much, due to the risks involved.

Here is the code snippet:

            if pygame.font:
                 font = pygame.font.Font(None, 36)
                 text = font.render("Pummel the Chimp, and win $$$", 1, (10,10,10))
                 textpos = text.get_rect(centerx=background.get_width()/2)       #This is the variable that we want to change.
                 background.blit(text, textpos)   

    Also, if you guys could, it would really, really helpful if you could explain the code snippet with the code to us. Eg: what each syntax does. You don't have to, it's optional.

Thanks again (^_^)

-----------------------------------
apython1992
Tue Apr 12, 2011 12:04 pm

RE:Moving Text across a background
-----------------------------------
If you're afraid of messing up something you already have, just save what you know works as a backup file. Alternatively you could go with a source control system. In Pygame, it's very easy to move rectangle objects. If you can represent a block of text as a rectangle, do you think you can move the rectangle containing the text?

-----------------------------------
Notthebbq
Wed Apr 13, 2011 11:00 am

Re: Moving Text across a background
-----------------------------------
could you give example code?

-----------------------------------
apython1992
Wed Apr 13, 2011 11:08 am

RE:Moving Text across a background
-----------------------------------
If you're using the font module, you can render it into a surface object, which is an image that can be moved. I won't give you sample code, but this will be helpful: http://pygame.org/docs/ref/font.html

-----------------------------------
Notthebbq
Tue Apr 19, 2011 12:34 pm

Re: Moving Text across a background
-----------------------------------
my group member does not understand your previous statement: represent teh text block as a rectangle and would appreciate it if you could provide actual code please and thanks

-----------------------------------
apython1992
Tue Apr 19, 2011 1:07 pm

RE:Moving Text across a background
-----------------------------------
Use my last statement, about rendering it onto a surface object (in Pygame, a surface is an image-like object that can be moved) and then getting its rectangle.

Font.render
draw text on a new Surface
Font.render(text, antialias, color, background=None): return Surface

Surface.get_rect
get the rectangular area of the Surface
Surface.get_rect(**kwargs): return Rect
Returns a new rectangle covering the entire surface. This rectangle will always start at 0, 0 with a width. and height the same size as the image.
