0

I'm doing a little game and it was time for collision part. So in my game you can shoot bullets and kill enemies, but to detect collision I don't know what is better: rect.colliderect() or sprite.spritecollide().

I'm working with sprite and what is the better to detect collision? I couldn't find anything on the internet to answer to my question.

    def collision(self):
        #if self.rect.colliderect(ennemi.rect):
            #print("collision")
        if pygame.sprite.spritecollide(bullet, ennemi_group, True):
            print("collision")

    def update(self):
        ...
        self.collision()
        ...
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Siiyu
  • 43
  • 4
  • `colliderect` is for `pygame.Rect` objects. `sprite.spritecollide` is for `sprite.Sprite`s and `sprite.Group`s. `pygame.sprite.spritecollide` uses `colliderect` under the hood. None of these are worse or better because they are for different use cases. – Rabbid76 Jan 03 '22 at 17:50
  • thx man, really appreciate :) – Siiyu Jan 03 '22 at 18:07

0 Answers0