We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › getting mouseX and Y values
Page Index Toggle Pages: 1
getting mouseX and Y values (Read 704 times)
getting mouseX and Y values
Sep 21st, 2007, 11:15pm
 
Is it true that I can only get a value at one time per a frame (that is, one time at an execution of draw() function)...

I wrote a code, that prints out delayed time using millis() function, and mouseX value at the beginning of draw(). Then it has the for-statement like "for(int i=0; i<10000; i++)". After that, it print out delayed time and mouseX, again.
I found difference at two time value but got the same value for mouseX.

Though my question seems true with the above experiment, I just want to make sure it.
Re: getting mouseX and Y values
Reply #1 - Sep 22nd, 2007, 8:06am
 
yes. mouse values are set in between draw()s, once per frame.

Code:

void draw()
{
println ( mouseX + " " + mouseY );
delay( 1000 );
println ( mouseX + " " + mouseY );
println("");
}
Re: getting mouseX and Y values
Reply #2 - Sep 23rd, 2007, 9:49am
 
to get values more than once per frame, use the mouseMoved(), mousePressed(), or mouseDragged() events:

http://processing.org/reference/mouseMoved_.html
http://processing.org/reference/mousePressed_.html
etc.

these events will be queued to the end of draw(), then called in succession. the mouseX/Y values will be updated on each call.
Page Index Toggle Pages: 1