Example #1
0
    def __init__(self, w=None, filename=None, image=None, colorkey=TRANSPARENT, alpha=0, convert=1):
        """
            Create sprite from file or surface
        """
        Graphics.__init__(self, w)
        if filename is None and image is None:
            if self.filename is None:
                self.image = load_image('None.png', convert=convert)
            else:
                self.image = load_image(self.filename, convert=convert)
        elif image is None:
            self.image = load_image(filename, convert=convert)
        else:
            self.image = image

        if alpha:
            self.image.set_alpha(alpha, pygame.locals.RLEACCEL)
            self.image.convert_alpha()

        if colorkey is not None:
            self.image.set_colorkey(colorkey)
            if not alpha:
                self.image.convert()

        self.rect = self.image.get_rect()
        self.set_position((0, 0))
        self.set_collision_rect(self.rect)
Example #2
0
    def set_background(self, filename=None, img=None, tilename=None, tile=None, color=None):
        """ set the background.
        filename: Name of the full-screen background image.
        img: Full-screen background image. (pygame Surface)
        tilename: Name of tile image.
        tile: Tile image. (pygame Surface)
        color: Solid background color.

        """
        if filename is not None:
            background = load_image(filename)
        elif img is not None:
            background = img

        if tilename is not None or tile is not None:
            if tilename:
                tile = load_image(tilename)
            background = pygame.Surface(self.size).convert()
            for y in range(0, self.size[1], tile.get_height()):
                for x in range(0, self.size[0], tile.get_width()):
                    background.blit(tile, (x, y))

        if filename is None and img is None:
            if color is None:
                color = BLACK
            background = pygame.Surface(self.size).convert()
            background.fill(color)
             
        if hasattr(self, '_background'):
            self._background.blit(background, (0, 0))
        else:
            self._background = background
        self._foreground.blit(self._background, (0, 0))            
Example #3
0
    def add(self, filename='default', image=None, colorkey=TRANSPARENT, convert=1):
        """add image to list of available images """

        if image is None:
            image = load_image(filename, convert)
        if colorkey is not None:
            image.set_colorkey(colorkey)

        self.images[filename] = image
        if self.defaultImage == 'None.png':
            self.delete('None.png')
            self.defaultImage = filename