Reputation: 2467
I have a GIF which I want to read each pixel individually to create accurate collision detection. Those GIF's contain transparent background. My code looks like:
for x in range(player_image.get_width()):
for y in range(player_image.get_height()):
col = player_image.get_at((x, y))
print col[3]
The problem is that every print contains 255 value while in the given image almost half of the image is transparent (background). All other values (red, green, blue) are correct. So, how can I read surface pixel's alpha channel value?
Upvotes: 0
Views: 224
Reputation: 4451
You can convert_alpha()
your image after loading it:
player_image = pygame.image.load(...).convert_alpha()
That way your image will have per pixel alpha values.
Upvotes: 2