Mouse Clicked on Image in Pygame

So, now that our image can animate and wrap around the screen, let’s try to click on it!

First, though we should just take moment to learn about how the mouse itself works in pygame.

Download Code
Download Code

The important new lines which are now part of our game loop is to constantly look to see if the mouse click event is fired (line 21) and then, if so, to see if the x,y coordinates of the mouse are inside the rectangle (line 24)

pygame-mouse-event-example-code

Full Code