Can someone tell me how to implement collision in Pygame?
For example I have a sprite called A and another one called B.
How do I detect if they collide in Pygame?
migrated from stackoverflow.com Jul 23 '11 at 16:14
Take a look at:
And the several methods following it. You can test against a rectangle, circle, mask, sprite, or group of sprites.
You probably want
Which checks if two sprites collide based on their bitmasks.
I use collisions based on rectangles. Both sprites need a .rect assigned to them.
Then check for a collision
Alternatively you can use the rectangle to check for a collision, eg
I use rect collisions because they're faster than bitmap checks.
Pygame rect docs http://www.pygame.org/docs/ref/rect.html