Question

These are the parts of the code that are relevant:

class t_color(object):
    BLUE = (0, 0, 255)
    GREY = (128, 128, 128)
    GREEN = (0, 128, 0)
    LIME = (0, 255, 0)
    PURPLE = (128, 0, 128)
    RED = (255, 0, 0)
    SILVER = (192, 192, 192)
    WHITE = (255, 255, 255)
    BLACK = (0, 0, 0)
    YELLOW = (255, 255, 0)

IMAGE_ALPHA = t_color.BLACK
...
img = pygame.image.load('images/' + str(i) + '.bmp')
img.set_colorkey(IMAGE_ALPHA)
g.images.append(img)

On windows this was working fine. Now that I'm using Mac (10.9) and python 2.7.5(on windows I had 2.7.6) pygame 1.9.2 (on windows I had 1.9.1)

Here are the images I'm useing, they are only 32x32 px: http://www.mediafire.com/download/nf9exc8trged687/images.zip

I want to set the black to be transparent as the images are BMP files and don't support transparency.

Does anyone know what is causing this or how to fix?

Was it helpful?

Solution

https://stackoverflow.com/a/13078080/3157252 -- Not mine, foudnd it

There's per-pixel alpha, colorkey alpha, and per-surface alpha. You're asking for colorkey.

When you call convert_alpha() it creates a new surface for per-pixel alpha.

And from set_colorkey

The colorkey will be ignored if the Surface is formatted to use per pixel alpha values.

So: Load image with .convert() Since you want to use a color key. Then call set_colorkey.

Also, I saw nothing in the docs about passing "-1" as first argument to set_colorkey.

That's probably from a tutorial, which has a load_image function to grab the topleft pixel's color value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top