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 › how can I stop/start animation
Page Index Toggle Pages: 1
how can I stop/start animation? (Read 1440 times)
how can I stop/start animation?
Jan 22nd, 2010, 9:50am
 
I have a problem, I am design an animation using processing..  and I want to add pause specification. How can I stop drawing?
for example, when a pressed space bar, programs stops, then starts if I press space bar again.
Re: how can I stop/start animation?
Reply #1 - Jan 22nd, 2010, 10:40am
 
http://processing.org/reference/loop_.html

//Stop draw()
noLoop();

//Start draw()
loop();
Re: how can I stop/start animation?
Reply #2 - Jan 23rd, 2010, 4:41am
 
alternatively you can also create an boolean, which you set to true and false. This depends on the event, that you want to toggle the animation with. mousePressed and keyPressed are always called, but you also might use an event, which is stoped by noLoop() as well. In this case its better to use a boolean:

Code:
boolean doSth = true;

void setup(){
}

void draw(){
if(doSth){ //-> if doSth == true
println("I'm doing somthing!");
//put your animation here
}
else println("I'm bored");
}

void keyPressed(){
if(key=='d') doSth = true;
else doSth = false;
}
Page Index Toggle Pages: 1