Runeony1
Runeony1

Reputation: 229

Processing draw() method use not working

I have code that changes the color and opacity of a PShape, I was debugging it and I'm 99% sure all the methods work. I made a delay method because Processing doesn't have a built-in delay method anymore. When I was debugging it I noticed that it would only draw what it was supposed to after all the delay calls where done (it would draw the latest version of the PShape when there was no more delays). So I looked at my delay method and I messed around with it but still no correct outcome. Can someone try to explain to me why PShape is not updating?

EDIT* I received an answer telling me to use noLoop(), I googled how to use it but I can't seem to find the correct place to put it. I've tried the very first line in the flash method, in setup (but then I realized I had live buttons that weren't updating)

The code below that makes a PShape's flash twice:

    noLoop();      
root.setVal(newVal);
root.highlight(0,255,0);
root.setopacity(200);
redraw();
try {Thread.sleep((long)1500);} 
catch (InterruptedException ex) {println("Error!");}
root.setopacity(0);
redraw();
try {Thread.sleep((long)1500);} 
catch (InterruptedException ex) {println("Error!");}
root.setopacity(200);
root.clearHL();//just to make sure I repeated these methods
root.highlight(0,255,0);
redraw();
try {Thread.sleep((long)1500);} 
catch (InterruptedException ex) {println("Error!");}
root.clearHL();
redraw();
loop();
return root;

Upvotes: 0

Views: 1110

Answers (1)

Serdalis
Serdalis

Reputation: 10489

You need to show more of your code (for example the setup function),
however your problem seems to stem from that fact that you may not have called noLoop(); before trying to manually redraw objects.

This will cause the object to flash up for a frame before being overwritten by Processings automatic redraw.

As an aside, you can use a Timer for such things as delays if you so wish.

Or use Sleep:

import java.lang.Thread.*;

noLoop();
root.setVal(newVal);
root.highlight(0,255,0);
root.setopacity(200);
redraw();
Thread.sleep(1500);;
root.setopacity(0);
redraw();
Thread.sleep(1500);
root.setopacity(200);
root.clearHL();//just to make sure I repeated these methods
root.highlight(0,255,0);
redraw();
Thread.sleep(1500);
root.clearHL();
redraw();

Upvotes: 0

Related Questions