0

So i'm trying to use collide point method on a button object that i've created but it doesn't have the collide point method and seems to only work on a rect. So is there a way to use this method but on an object.

this is the button class:

class Buttons():
    def __init__(self,x,y,image,scale):
    self.image=pygame.transform.scale(image, (200*scale, 100*scale))
    self.rect = self.image.get_rect()
    self.rect.topleft=(x,y)
    self.clicked=False 
AttributeError: 'Buttons' object has no attribute 'collidepoint'

However the error says attribute which i do not understand as i thought it was a method.

  • You don't inherit from `Sprite` – mousetail Jul 06 '22 at 10:51
  • @mousetail but its not a sprite its just for a button should i make it a sprite –  Jul 06 '22 at 10:53
  • Seems like the `collidepoint` function exists only on [rect objects](https://www.pygame.org/docs/ref/rect.html#pygame.Rect). While in pygame every drawable object should inherit from sprite you are facing a different issue. – mousetail Jul 06 '22 at 10:54
  • @mousetail but it is a rect object which is what im not understanding –  Jul 06 '22 at 10:57
  • 1
    No it's not. It's a `Buttons` object. Use `button.rect` to get the rect that belongs to the button – mousetail Jul 06 '22 at 10:58
  • @mousetail could you give an example of button.rect i cant find any and will you be able to use collide point on it –  Jul 06 '22 at 11:01
  • Where do you use `collidepoint`? Fix it there – mousetail Jul 06 '22 at 11:06

0 Answers0