Skip to content
Advertisement

How can a object detect the mouse in pygame

JavaScript

I have here the bubbles class and i want to do it that when you click a bubble it despawns but i dont know how the bubbles detect the mouse cursor and how the bubbles despawn. I already tried to add the mouse position function but I dont know hot to use it. And I searched on the Internet but I found nothing about that.

JavaScript

Here is where everythings run from the code

JavaScript

Thanks for Helping

Advertisement

Answer

“Despawn” a bubble by calling pygame.sprite.Sprite.kill. kill remove the Sprite from all Groups. Use the MOUSEBUTTONDOWN event and pygame.Rect.collidepoint to determine if a bubble is clicked:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement