New to pygame, writing a little code to try and detect collisions. Here is a small test file I wrote up to demonstrate the error. It instantiates two sprites, and tries to detect collision between them
import pygame
class Box(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
class Circle(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
box = Box()
circle = Circle()
group = pygame.sprite.Group()
group.add(circle)
pygame.sprite.spritecollideany(box, group)
However this returns an error:
default_sprite_collide_func = sprite.rect.colliderect
^^^^^^^^^^^
AttributeError: 'Box' object has no attribute 'rect'
I'm not really sure what I should be doing to remedy the situation. How can I detect collision between two sprites in pygame?
NOTE: edited to include proposed solution from an answer. I'm not making a new question since I'm still getting a similar error.