pmouseX not updating?

edited September 2015 in Questions about Code

hi,

I'm trying to check if my user moved his mouse since the last time he pressed, but the pmouseX is always the same as my mouseX. In the reference it says "inside mouse events, they update each time the event is called", so the previous position should be updated to pmouseX / pmouseY when i click again right? Atm it just gives me the same number. here's the code:

void mousePressed() 
{
    println("old x: " + pmouseX + " - new x: " + mouseX);
}

Answers

  • The problem is that you're only tying into one event. There are many other events: mouseMoved and mouseDragged for example.

    So pmouseX and pmouseY don't contain the x and y values of the last mousePressed() function, they return the x and y values of the last mouse event, whatever that was (probably mouseMoved). And since you just moved the mouse to the location you clicked, that will always be the same as mouseX and mouseY.

    If you want to keep track of the last location you clicked, you'll have to store that in your own variables.

  • Oh Gotcha! Makes sense.

Sign In or Register to comment.