Hi, so basically I want my code to be so that if my cursor is touching a circle, a score will be updated by one point only until the cursor leaves and touches the circle again. However, currently, a point keeps on being added for every frame that the cursor is on the circle. How can I change this? Thanks
Here is the relevant code:
circle(x, y, 20)
if dist(x, y, mouseX, mouseY) <= 20:
score = score + 1
Without clicking the circle, just hovering…?
You’ve already done half the work, good job! And you even correctly identified what your problem is: The condition you’ve created is true whenever the mouse is inside the circle. However, what you really want, is to check whether the mouse was not in the circle the frame before, but is now.
To do this, you can use the
pmouseY variables. They tell you where the mouse was the frame before. You can read more on them here:
Try and solve your problem with this information. If you still need help, feel free to ask!