0

I am trying to get the rect of the circle in the draw method but Pygame gives an error everytime I call the get_rect() method on my Alien instance. I want a dynamic circle surface for collision detection because my code generates different random size of circles. Please any help will be greatly appreciated

class Alien():
    def __init__(self, etc):
        self.x = random.randrange(0,600)
        self.y and self.size are also random variables

def draw(self, screen, colour):
        pygame.draw.circle(screen, colour, (self.x, self.y), self.size)

I want to get the rect of this circle from the draw method but it doesn't have a rect method. I checked online and i saw you could use pygame.surface but I don't know how to use it to generate a surface for my circle taking into consideration that when I generate 20 different Alien circle object, they w

jh314
  • 27,144
  • 16
  • 62
  • 82
tushortz
  • 3,697
  • 2
  • 18
  • 31
  • 1
    I honestly don't understand your question. I'd stick to the typical minimal example code along with a description of what happened and what you expected instead. – Ulrich Eckhardt May 25 '15 at 08:45

1 Answers1

1

All drawing functions of the pygame.draw module return a rectangle representing the bounding area of changed pixels.

Update your draw() method

def draw(self, screen, colour):
    return pygame.draw.circle(screen, colour, (self.x, self.y), self.size)

to return a pygame.Rect object which you could use e.g. for collision detection.

elegent
  • 3,857
  • 3
  • 23
  • 36