|
Author |
Topic: Pausing a Sketch (Read 423 times) |
|
skloopy
|
Pausing a Sketch
« on: Apr 12th, 2004, 8:40am » |
|
Im making a load sketch that's gonna open up other sketches in a window, but I want to make the loader sketch pause so it's not trying to draw anything while the other window is open. I've tried to set the framerate to zero, which doesn't work, and near-zero (.001) but near zero means that the user is gonna have to wait a long time for mousePressed to be called after they click to start the applet again. Is there a way to pause the loop thread directly and then resume it on a mouseclick? I've noticed i'm starting to explain things like im writing a program or something
|
|
|
|
amoeba
|
Re: Pausing a Sketch
« Reply #1 on: Apr 12th, 2004, 10:37am » |
|
An easy trick is using a boolean variable and set it to true or false, depending on whether your "loader sketch" should draw. framerate() only acts as a guideline for how fast your sketch will run, and suspending the thread will most likely just get you in trouble. Try something like this: Code:boolean doDraw; void setup() { .. doDraw=true; .. } void loop() { if(doDraw) { // Draw the stuff } } void load() { // Load new stuff, whatever that means doDraw=false; } |
|
|
« Last Edit: Apr 12th, 2004, 10:38am by amoeba » |
|
marius watz // amoeba http://processing.unlekker.net/
|
|
|
skloopy
|
Re: Pausing a Sketch
« Reply #2 on: Apr 12th, 2004, 9:10pm » |
|
okay thanks amoeba yeah your prolly right.. and if i include the background() call it'll look like it's paused! cool!
|
|
|
|
Eben Eliason Guest
|
Re: Pausing a Sketch
« Reply #3 on: May 3rd, 2004, 10:49am » |
|
I don't know about pausing the loop function, but it seems that the following might be all you really need: boolean paused = false; void loop() { if(!paused) runMyCode(); } void runMyCode() { //your current loop code here... } void mousePressed() { paused = !paused; }
|
|
|
|
|