LearningProcessing icon indicating copy to clipboard operation
LearningProcessing copied to clipboard

Exercise 20-1, SoundFile requires reference to "this"

Open shiffman opened this issue 10 years ago • 0 comments

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.

shiffman avatar Sep 07 '15 22:09 shiffman