I'm bumping my own thread, since I'm learning processing in a rather eclectic fashion. Jumping from idea to problem, to idea, to problem, et cetera. I'd rather not create a thread per question.
I get a nullpointerexception at the for loop in the update function, but can't seem to find what I am doing wrong. My goal is to write a simple class that creates a buffer of PVectors, and shifts down the PVectors upon calling the update function.
Thanks in advance.
Quote:BufferXY newBuffer;
void setup(){
background(0);
size(200,200);
}
void draw(){
newBuffer = new BufferXY(10, mouseX, mouseY);
newBuffer.update();
}
class BufferXY{
PVector[] vectors;
int buffersize;
float xpos;
float ypos;
BufferXY(int buffersize_,float xpos_,float ypos_){
buffersize = buffersize_;
xpos = xpos_;
ypos = ypos_;
//create the buffer
PVector[] vectors = new PVector[buffersize];
//fill the array with "empty" vectors.
for (int i = 0; i <vectors.length; i++){
vectors[i] = new PVector(0,0,0);
}
}
void update(){
//shift the values down one spot
for (int i = 0; i < vectors.length-1; i++){
vectors[i] = vectors[i+1];
}
//add a new position on the last spot.
vectors[vectors.length-1] = new PVector(xpos, ypos, 0);
}
}
Oh and I'm using the book "Learning Processing" by Shiffman, which is really helpful and understandable for someone with a non-technical background.