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

Re: [pygame] Starting with pygame



If you just want a solid color, use surface.fill((#color))
You can blit other things on top of it, (like clouds and airplanes) as follows.
Otherwise, do surface.blit(background, (0,0))
where background is a surface:
background = pygame.image.load(#background image path)
For example:

import pygame
pygame.init()
surface = pygame.display.set_mode((800, 640))
cloud = pygame.image.load(#path to cloud image)
airplane = pygame.image.load(#path to airplane image)
while True:
    surface.fill((150,150, 255)) #make a light blue background
    surface.blit(cloud, (cloudxpos, cloudypos)
    surface.blit(airplane, (planexpos, planeypos)
    pygame.display.flip()

or

import pygame
pygame.init()
surface = pygame.display.set_mode((800, 640))
background = pygame.image.load(#background image path)
cloud = pygame.image.load(#path to cloud image)
airplane = pygame.image.load(#path to airplane image)
while True:
    surface.blit(background, (0,0))
    surface.blit(cloud, (cloudxpos, cloudypos)
    surface.blit(airplane, (planexpos, planeypos)
    pygame.display.flip()

I'm not sure, but I think surface.fill() is faster.  Someone should check that.

Ian