Pygame supports multiple methods for collision detection. The one presented in this tutorial will be pygame.sprite.spritecollide(sprite, group, dokill, collided = None). spritecollide gets a sprite and a group of sprites and returns a list of all sprites, which collides with the first sprite. Additionally you can define, if the collided sprites should be removed from the group or not. collided can be used to define the function, which should be used to decide, if two sprites collides. For more information you can take a look at Pygames documentation.
The interesting part in this demo is that the performance of the collision functions can be compared to each other. This is done by defining the collide parameter.
During the test we had 250 collision detection calls per frame.
It can be seen, that some functions are more expensive than others. It is up to you, to choose the best one.
No comments:
Post a Comment