0
rect1 = pygame.draw.rect(display, (125,125,125),(200,300,310,380))
if rect1.collidepoint(mouse_pos):
    #dosomething

This condition isn't working even when I click on the rect ,but if I use "<" or "=" or ">" sign instead of "collidepoint" it works

mouse_pos is event.pos,when I click on rect1 ,mouse_pos registers/becomes the coordinate of rect1

What is the problem , why it is not working?

  • In general there is no problem with `rect1.collidepoint(mouse_pos)`. What is `rect1`? Wher do you get it from? Please read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Show the code which works (_""_) and show the code which doesn't work (`rect1 = ...`) – Rabbid76 Jun 22 '21 at 14:41
  • rect1 is a rectangle I created on screen – Appar Patel Jun 22 '21 at 15:01
  • This is not helpful. I know that `rect1` is a rectangle. How do you create `rect1`? You have to show the code. There is nothing wrong with `rect1.collidepoint(mouse_pos)` – Rabbid76 Jun 22 '21 at 15:05
  • Possibly you'll find some help here: [Pygame mouse clicking detection](https://stackoverflow.com/questions/10990137/pygame-mouse-clicking-detection/64533684#64533684) – Rabbid76 Jun 22 '21 at 15:06
  • There is nothing wrong with this code. – Rabbid76 Jun 22 '21 at 15:32

0 Answers0