PShape array assigned to createShape(void) issue
in
Programming Questions
•
8 months ago
Hello guys
createShape();
i call an pshape array
PShape[] test = new PShape [20];
in a class
class ShapeClass
when i assign vertex to a custom PShape created from the PShape array i can't only initialise in the class the createShape function like this:
class Ball {
float x;
float y;
float w;
float h;
final float fx=0;
final float fy=0;
int index = 0;
PShape[] test = new PShape[8] ;
Ball(float tempX, float tempY, float tempW, float tempH, int index_) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
index = index_;
}
void initShape() {
for (int i = 0; i<8; i++) {
test[i] = createShape();
test[i].fill(0);
}
}
void setShape(int currentNombre, boolean start) {
currentNombre = index+1;
println(currentNombre);
for (int i=0; i<currentNombre; i++) {
if (currentNombre>= 0) {
//test[currentNombre]=createShape();
test[currentNombre].vertex(this.x, this.y);
test[currentNombre].vertex(this.x+20, this.y);
test[currentNombre].vertex(this.x+20, this.y+20);
test[currentNombre].vertex(this.x, this.y+20);
}
test[currentNombre].end(CLOSE);
shape(test[currentNombre]);
}
}
i call initshape() in void setup() and setShape() in void draw(); but it still doesn't work : i get a NPE...
Need I use createShape() in each frame?
So i can't assign createShape to my pshape array in void setup()? This is a serious issue because he burns so much memory ...
Please, I need your help sir
Thanks in advance.
1