I’m writing a game in Python with Pygame, and I’m trying to keep my player sprite from touching trees dotted around the map. My player’s sprite has transparency (of course), and when I load a Pygame Mask with pygame.mask.from_surface(self.getNextFrame()), it only loads the parts with actual color.
My question is, does anyone know how to get pygame to load the mask WITH the transparency from the original image?
Yes, use the second argument:
By setting it to
0any pixel is seen as opaque. See the documentation.Please note that the result of this is simply a rectangle of the size of the surface. So it might actually be more performant to use this: