Reputation: 5055
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
Upvotes: 0
Views: 1349
Reputation: 4007
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.
Upvotes: 1