I have been writing a test function to learn how a mouse \'click\' action on a pygame.rect will result in a reponse.
So far:
def test():
pygame.i
Well, if anyone is interested or is having a similar issue, this is what I needed to change.
First off the, remove:
button = button.get_rect()
Then:
screen.blit(button, (300, 200))
Should be:
b = screen.blit(button, (300, 200))
This to create a Rect
of the area of where the button is located on the screen.
On to:
if event.type == pygame.mouse.get_pressed()
I changed to:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
The pygame.mouse.get_pressed()
gets the state of all three mouse buttons (MOUSEBUTTONDOWN, MOUSEBUTTONUP, or MOUSEMOTION). I also needed to add in event.button == 1
to specify that this was the 'left-mouse' button being pressed.
Finally:
`if button.collidepoint(pos):`
to:
`if b.collidepoint(pos):`
Using Rect
b's collidepoint method
I think rect method call collidepoint, not collide*r*point. Here is the link to documentation!