[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] fundamental (stupid) question about blitting part of a background image
- To: pygame-users@xxxxxxxx
- Subject: [pygame] fundamental (stupid) question about blitting part of a background image
- From: "Horst F. JENS" <horst.jens@xxxxxx>
- Date: Sat, 04 Feb 2006 02:18:03 +0100
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Fri, 03 Feb 2006 20:18:13 -0500
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Thunderbird 1.5 (Windows/20051201)
Sorry if this question is very stupid, but i have troubles with the
pygame documentation in this point.
I play around with the 'stars.py' demo from pygames and want to draw my
stars not on empty black but instead on a background image (a almost
white picture).
i have a list of stars [age, velocity, position] and 3 functions:
(kill_stars: (paint the stars in white, background-like-color))
move_stars: paint nothing, calculate new position for each star, return
MinX, MinY, MaxX, MaxY of the stars array
draw_stars: paint the stars (pygame.draw.circle) in black, the
foreground-color
i can "paint" my stars but while doing so i slowly destroy my background
image. (code see below) I need a method to copy/clipping a part of my
background image at a given position but i found no examples how to do that.
If i use the out-commented code behind the ## chars all i get is a big,
black rectangle without nether stars nor background in it.
Could you give me some hints ?
thank you in advance,
/Horst
pygame.init()
screen = pygame.display.set_mode(WINSIZE)
pygame.display.set_caption('pygame Stars Example')
white = 255, 240, 200
black = 20, 20, 40
#create the background, tile the bgd image
bgdtile = load_image('background.jpg', -1)
# -1 avoid conversion to transparent background
background = pygame.Surface(SCREENRECT.size)
for x in range(0, SCREENRECT.width, bgdtile.get_width()):
for y in range(0, SCREENRECT.height, bgdtile.get_height()):
background.blit(bgdtile, (x, y))
screen.blit(background, (0,0))
#main game loop
done = 0
pygame.display.update()
NoMoreStars = False
while not done:
kill_stars(screen, stars, white) # delete
# this code just make a black rectangle:
##oground = pygame.Surface(Rect(MINX
## ,MINY,MAXX-MINX,MAXY-MINY).size)
##screen.blit(oground, (MINX,MINY))
MINX, MINY, MAXX, MAXY = move_stars(stars, NoMoreStars)
draw_stars(screen, stars, black) # draw new
pygame.display.update(MINX,MINY, MAXX-MINX, MAXY-MINY)
##pygame.display.update()