Reputation: 179
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')
Upvotes: 2
Views: 1037
Reputation: 101042
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.
Upvotes: 3