user3426943
user3426943

Reputation:

Python 2.7.7/Pygame - How to detect if the mouse is within a circle?

Hi I am trying to make a punny cookie clicker type game called py clicker and made an invisible circle over the sprite which is a pie. How do I detect if the mouse is within the circle so when the user clicks it checks if it is in the circle and adds one to the counter?

Upvotes: 0

Views: 139

Answers (3)

Jason Sperske
Jason Sperske

Reputation: 30446

If you know the x,y of the center of the circle and it's radius then you can calculate the distance from the center of the circle to your mouse pointer when you click. If it's greater than the radius then you are outside. There is a built in method that might help called math.hypot that will return the length between two points.

Upvotes: 2

Maddy
Maddy

Reputation: 2060

you can use the graphics library and use the method called getMouse.

Upvotes: 0

furas
furas

Reputation: 143197

You could try pygame.sprite.collide_circle() . But you will need another Sprite with small radius and mouse position.

Upvotes: 1

Related Questions