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 › using custom methods inside PGraphics beginDraw();
Page Index Toggle Pages: 1
using custom methods inside PGraphics beginDraw(); (Read 864 times)
using custom methods inside PGraphics beginDraw();
Mar 13th, 2010, 3:52pm
 
I'd like to invoke a drawing method in an offscreen buffer, but I cant get it to work:

    buffer.beginDraw();
    buffer.background(255,0);
   buffer.myBlobs[i].update(inc);
   buffer.endDraw();

doesnt work: myBlobs is an array of objects from my blob class. They have a method called update to draw them. Inc is used to influence the noise().

How do I draw to an offscreen buffer with a local method?

i tried:
class blob extends PGraphics

to no avail...
Re: using custom methods inside PGraphics beginDraw();
Reply #1 - Mar 13th, 2010, 6:04pm
 
Coincidentally, just tonight I am trying to do something very similar (and also having problems).

Is buffer global? The update method needs to draw on buffer, within the class...rather than trying to do buffer.myBlobs[i].update(inc); This won't work as buffer doesn't have a myBlobs[i].update(inc) method.
Re: using custom methods inside PGraphics beginDraw();
Reply #2 - Mar 13th, 2010, 7:41pm
 
You can always pass the PGraphics object that you want them to draw on to the class's drawing function.

myBlobs[i].update( inc, buffer );

class Blob {
//...
void update( int _inc ){
update( _inc, g );
}
void update( int _inc, PGraphics buf ){
buf.line(
//... etc.
}
}
Re: using custom methods inside PGraphics beginDraw();
Reply #3 - Mar 14th, 2010, 11:37am
 
Tx Tfguy. What a great idea to insert make two update methods!

I have a question about this line:
Code:
update( _inc, g ); 



i suppose  the idea is to make the update method run on the normal canvas if I don't pass it a buffer. But how do I define g to be this normal screen?
Re: using custom methods inside PGraphics beginDraw();
Reply #4 - Mar 14th, 2010, 11:20pm
 
g is already defined to be the normal screen. It's Processing magic.
Page Index Toggle Pages: 1