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 & HelpSyntax Questions › Slowly Increment with Mouse Interaction
Page Index Toggle Pages: 1
Slowly Increment with Mouse Interaction (Read 802 times)
Slowly Increment with Mouse Interaction
Sep 13th, 2009, 7:12pm
 
I'm trying to make a program that draws a series of images in succession, and changed with a mouse click.

The problem with the code below is that if the mouse is head for longer than the 200 millisecond delay, the image changes twice. Ideally, no delay would be involved, but the draw method would wait until mouse is released to cycle the image the next switch case.

How do I wait for mouse release? Can I use the mouseReleeased() method inside the switch?

Code:
int i= 0;

void setup() {
 size (700,700);

}
 void draw(){
 
 stroke(0);
 strokeWeight (5);
 background (50,200,200);

switch(i){
 case 0:
 
 line (10,40, 90, 400);
 if (mousePressed == true){
 
   i++;
delay(200);
 }
 
 break;
 case 1:
 line (10,40, 290, 500);
 if (mousePressed == true){
   
   i++;
   delay(200);
 }
 
 break;
  case 2:
 line (10,100, 490, 500);
 if (mousePressed == true){
   i=0;
   delay(200);
 }
 break;

}

 }
 
 

Re: Slowly Increment with Mouse Interaction
Reply #1 - Sep 13th, 2009, 8:27pm
 
i dont get the concept of your programm but thats probably not how you should do it. You should not use delay if you dont need to. Think about setting a timer using millis maybe.
Re: Slowly Increment with Mouse Interaction
Reply #2 - Sep 13th, 2009, 8:33pm
 
void mousePressed() is your friend.  It is called only when the mouse is initially pressed.
--Ben
Page Index Toggle Pages: 1