LearningProcessing
LearningProcessing copied to clipboard
Exercise 20-1, SoundFile requires reference to "this"
Because of the way SoundFile requires a reference to this, it can't be instantiated inside a class the same way. . because in the class this refers to the Doorbell class and not the main sketch. It can be fixed by doing the following:
doorbell = new Doorbell(this, width/2, height/2, 64, "doorbell.mp3");
and
Doorbell(PApplet parent, float x_, float y_, float r_, String filename) {
x = x_;
y = y_;
r = r_;
s = new SoundFile(parent, filename);
}
This is is tricky and confusing for a beginner. Probably better would be to make the SoundFile object in setup() and pass it in.