1

I am making a game with Python 3.3 and PyGame 1.9.1 using sprite sheets.
With my sprites, I use a lot of shading and gradient along the black outlines--to make it look sharper.

The problem is... I don't know of a proper method to cut out pieces of a sprite sheet without the loss of transparency.

Here are my couple image functions:

def load_image(file):
file = os.path.join(main_dir, 'data', file)
return pygame.image.load(file).convert_alpha()

This (above) one loads the image from my "data" folder Note: it does apply convert_alpha to the image.

def image_at(sheet, rectangle, colorkey = None, coords = (0,0)):
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size).convert()
image.blit(sheet, (0, 0), rect)
if colorkey is not None:
    if colorkey is -1:
        colorkey = image.get_at(coords)
    image.set_colorkey(colorkey, pygame.RLEACCEL)
return image

And this one cuts out a piece of an image (or, surface). Note: variable "sheet" refers to the image.

These couple functions work completely fine, and the colorkey does effectively remove the background... But the opacity is still lost.
In action, these functions look like:

img = load_image('SpriteSheet000.png')
Player.images = [image_at(img, (0,0,32,32), -1, (0,0),
                 image_at(img, (32,0,32,32), -1, (20,0))

More on the "image_at" function: the rectangle argument is the part of the image to cut out; the colorkey argument will either be None, (r,g,b), or -1; the coords argument is only effective if colorkey is set to -1, and it would choose a pixel on the image to use as the colorkey color.

I'm pretty new to PyGame, so please give me any help you can... Thank you.

BSasuke
  • 79
  • 1
  • 1
  • 7
  • Did you try [`pygame.Surface.subsurface()`](http://www.pygame.org/docs/ref/surface.html#pygame.Surface.subsurface) to get part of image without blitting. – furas Jul 20 '14 at 02:05

0 Answers0