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 › parent properties overridden
Page Index Toggle Pages: 1
parent properties overridden (Read 367 times)
parent properties overridden
Aug 14th, 2006, 12:42pm
 
Hi, i'm new to Processing,
i've started coding it with a simple test and now i've a question:

this is the code:

Code:

Paddle paddle;

void setup()
{
size(200, 200);
paddle = new Paddle();

}

void draw()
{
background(51); // clear screen
paddle.update();
}

class Paddle {

int width;

Paddle() {
this.width = 50;
}

void update() {

println("paddle width: " + this.width + " stage width: " + width);
}

}


how can i get the "stage width" if my object override the width properties ?
there's a solution other then avoid to use properties names in the object already bound by the PApplet ?

Re: parent properties overridden
Reply #1 - Aug 14th, 2006, 2:43pm
 
You could add a reference to your PApplet instance:
Quote:


Paddle paddle;

void setup(){
 size(200, 200);
 paddle = new Paddle(this);
}
 
void draw(){
 background(51); // clear screen
 paddle.update();
}  

class Paddle {  

 int width;
 PApplet p;
 
 Paddle(PApplet p) {
   this.width = 50;
   this.p=p;
 }
 
 void update() {
   println("paddle width: " + this.width + " stage width: " + p.width);
 }
}

Re: parent properties overridden
Reply #2 - Aug 15th, 2006, 5:12pm
 
thanks
Page Index Toggle Pages: 1