2

I would like to create physics body around the physical paths of the texture (cutting out alpha channel). How to do it in pygame? Is it going to be effective?

player_idle = pygame.image.load('data\img\player\idle\idle-1.png')
mikazz
  • 159
  • 1
  • 11

1 Answers1

3

You can use the mask module, especially the pygame.mask.from_surface() function:

Creates a Mask object from the given surface by setting all the opaque pixels and not setting the transparent pixels.

Then you can store the resulting Mask object as mask-attribute in your Sprites and e.g. use pygame.sprite.collide_mask() for pixel-perfect collision detection.

sloth
  • 99,095
  • 21
  • 171
  • 219