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 › Question about classes
Page Index Toggle Pages: 1
Question about classes (Read 311 times)
Question about classes
Jan 15th, 2009, 4:45pm
 
Can classes have their own separate draw command?  Im trying to make a bunch of shapes that are going to fall and rotate at the same time, and the easiest way I can think of doing it is to have one class that rotates them.  Ive tried to use the Draw() command but it doesn't seem to work.  Would a while(true) loop work?  Thanks!!
Re: Question about classes
Reply #1 - Jan 15th, 2009, 4:54pm
 
Do you mean:

Code:

void setup(){
DrawableClass drawableClass = new DrawableClass();
}
void draw(){

  drawableClass.draw();
  drawableClass.update();
}


class DrawableClass{
   int posY = 0;
   int rot = 0;
   void draw(){
    pushMatrix();
    translate(0,posY);
    rotate(rot);
    //draw shape
    popMatrix();
   }
   void update(){
     posY++;
     rot += 0.01;
   }
}


?

Could you post an example of what you want to do?
Re: Question about classes
Reply #2 - Jan 15th, 2009, 5:31pm
 
The answer to the first question is "yes".
But don't expect Processing to automagically call this draw() method in each class instance... You have to iterate over the objects and manually call the method.
You will find plenty of examples in the forum, for example in Lists' objects interaction mess. Note that lot of people call the method display() instead, probably to reduce confusion...
Re: Question about classes
Reply #3 - Jan 15th, 2009, 5:32pm
 
That actually answered my question.  Thanks a  lot!
Page Index Toggle Pages: 1