I have an image:
newGameButton = pygame.image.load("images/newGameButton.png").convert_alpha()
I then display it on the screen:
screen.blit(newGameButton, (0,0))
How do I detect if the mouse is touching the image?
Use Surface.get_rect
to get a Rect
describing the bounds of your Surface
, then use .collidepoint()
to check if the mouse cursor is inside this Rect
.
Example:
if newGameButton.get_rect().collidepoint(pygame.mouse.get_pos()):
print "mouse is over 'newGameButton'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With