Ich mache ein wirklich grundlegendes Tutorial über ArrayList/Particle-Systeme. Ich bekomme immer einen "Konstruktor ist undefined Fehler" und ich kann nicht herausfinden, warum. Googeln bringt viele kompliziertere Fragen/Antworten mit sich. Was vermisse ich? Hat sich das im letzten Jahr geändert?Konstruktor nicht definiert [Verarbeitung]
ArrayList<Particle> plist;
void setup(){
size(640, 360);
plist = new ArrayList<Particle>();
println(plist);
plist.add(new Particle());
}
void draw(){
background(255);
}
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
float lifespan;
Particle(PVector l){
// For demonstration purposes we assign the Particle an initial velocity and constant acceleration.
acceleration = new PVector(0,0.05);
velocity = new PVector(random(-1,1),random(-2,0));
location = l.get();
lifespan = 255;
}
void run(){
update();
display();
}
void update(){
velocity.add(acceleration);
location.add(velocity);
lifespan -= 2.0;
}
void display(){
stroke(0, lifespan);
fill(175, lifespan);
ellipse(location.x, location.y,8,8);
}
boolean isDead(){
if(lifespan < 0.0){
return true;
}else{
return false;
}
}
}
Ahh ok. Konstruktoren und Klassen sind neu für mich. Fehler ist weg. Ich werde etwas über Konstruktoren lesen. –
@mishap_n Wenn es um Parameter geht, sind Konstruktoren vielen Funktionen ähnlich. Sie erhalten einen ähnlichen Fehler, wenn Sie versuchen, die Funktion 'ellipse() 'ohne Parameter aufzurufen. –