topical media & game development

talk show tell print

graphic-processing-learning-20-example-20-2-example-20-2.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 20-2: Doorbell with Sonia
  
  // Import the Sonia library
  import pitaru.sonia_v2_9.*;
  
  // A sample object (for a sound)
  Sample dingdong;
  
  // A doorbell object (that will trigger the sound)
  Doorbell doorbell;
  
  void setup() {
    size(200,200);
    // Start Sonia engine.
    Sonia.start(this); 
    
    // Create a new sample object.
    dingdong = new Sample( "dingdong.wav" );
    
    // Create a new doorbell
    doorbell = new Doorbell(150,100,32);
    smooth();
  }
  
  void draw() {
    background(255);
    // Show the doorbell
    doorbell.display(mouseX,mouseY);
  }
  
  void mousePressed() {
    // If the user clicks on the doorbell, play the sound!
    if (doorbell.contains(mouseX,mouseY)) {
      dingdong.play();
    }
  }
  
  // Close the sound engine
  public void stop() {
    Sonia.stop();
    super.stop();
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.