Search code examples
pythonpygamecollision-detectionsprite

How to divide sprite into smaller parts in pygame?


No i don't ask about spritesheets. I'm working on a game in pygame and I want to know if it's possible to divide sprite into parts like body parts and then use it in collision-detection with pygame.sprite.groupcollide?


Solution

  • The default Sprite class has no notion of separate parts of a sprite; the whole thing is assigned a single bounding box. If you plan on using pygame.sprite.groupcollide it seems like you don't want an individual sprite anyway, you want them packaged together in their own group. Keep in mind that the pygame.sprite.Group.add method can take either a single sprite OR an iterable of sprites. So you can nest sprite groups if necessary.