Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm having a strange issue that I cannot seem to remedy. I am doing some prototyping with Pygame on a desktop running windows and a laptop running OS X. Both are running python v2.7.3 (installed via homebrew for the Macbook) and pygame v1.9.1.

For transparency, I have been using set_colorkey with a transparency color of (255, 0, 255). Here is the applicable code:

transColor = pygame.Color(255, 0, 255)
image = pygame.image.load(playerPath + "idle.png").convert()
image.set_colorkey(transColor)

This works flawlessly on my windows machine. On my laptop, it does not work. It just shows the hideous magenta color. Here's the strange part. If I change the transColor to (0, 0, 0), all black pixels in my images are transparent. Has anyone run into this issue before?

share|improve this question
    
Sounds like a premultiplied alpha issue. –  Tetrad Jan 22 '13 at 23:25
    
have you tried convert_alpha() instead of convert()? I thought that's the recommended one to use for surfaces with transparency. –  Jan Jan 23 '13 at 10:02
    
I tried convert_alpha() and it yielded the same result. I ended up just using PNG transparency rather than the colorkey –  Nathan Chowning Jan 24 '13 at 15:38
add comment

2 Answers

Interesting. My guess is that the Convert call is changing the image into a form that does not have the 255,0,255 colour in it any more. You may need to read a pixel from the converted image which you know to be the transparent colour, and then set that as the colour key.

eg.:

image = pygame.image.load(playerPath + "idle.png").convert()
transColor = image.get_at((0,0))
image.set_colorkey(transColor)
share|improve this answer
    
This did work (grabbing the color at 0,0) but there were some instances that I did not want to use that color as a transparency. –  Nathan Chowning Jan 24 '13 at 15:37
    
An alternative might be to have a 1x1 image of just the transparent colour, convert that, and extract the key colour from that image. The format should be the same across all images that are converted to the screen's optimal format. –  Kylotan Jan 24 '13 at 16:10
add comment

After digging around a bit more, I found that only a handful of the images weren't displaying the transparently properly (namely the background images - which made it difficult to see that the foreground images were working). As I'm using PNGs, I know that a lot of people have had issues using set_colorkey() when there are alpha channels already present. Instead of continuing to troubleshoot this annoying bug, I opted to just drop the colorkey stuff from my code and use the built-in PNG transparency.

I guess that's not really an answer... but it's a resolution!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.