Calling the extended class from the class that's being extended...
Quick and dirty fix.
Quote:
rectPos rect01;
void setup(){
size(200,200);
background(150);
rect01 = new rectPos(width/2, height/2, 50, 60);
}
void draw(){
rect01.show();
if(rect01.count<3){
rect01.update();
}
}
class rectPos{
int x;
int y;
int sizeX;
int sizeY;
int count=1;
rectDraw rd;
rectPos(int _x, int _y, int _sizeX, int _sizeY) {
x=_x;
y=_y;
sizeX=_sizeX;
sizeY=_sizeY;
rd = new rectDraw();
}
void update(){
x=x/2;
y=y/2;
sizeX=sizeX/2;
sizeY=sizeY/2;
count++;
}
void show(){
rd.display(x,y,sizeX,sizeY);
}
}
class rectDraw {
float x;
float y;
float sizeX;
float sizeY;
rectDraw() {
}
void display(float _x, float _y, float _sizeX, float _sizeY) {
x=_x;
y=_y;
sizeX =_sizeX;
sizeY =_sizeY;
rect(x,y,sizeX,sizeY);
}
}
Google "inheritance" and "polymorphism" for more info how to extend classes.
Or read
How my Dog learned PolymorphismSimpler: place the display function inside the rectPos class. Unless different classes are going to use the rectDraw class.
Quote:
class rectPos {
int x;
int y;
int sizeX;
int sizeY;
int count=1;
rectPos(int _x, int _y, int _sizeX, int _sizeY) {
x=_x;
y=_y;
sizeX=_sizeX;
sizeY=_sizeY;
}
void update(){
x=x/2;
y=y/2;
sizeX=sizeX/2;
sizeY=sizeY/2;
count++;
}
void display() {
rect(x, y, sizeX, sizeY);
}
}