Help with button options
in
Contributed Library Questions
•
3 months ago
Hi, I am trying to build an app that plays a number of different samples when different parts of the screen are touched. How do I define the different squares in the code below? Any help would be very much appreciated. Tim
Maxim maxim; AudioPlayer player; AudioPlayer player2; boolean buttonOn; boolean buttonOn2; void setup() { size(500, 500); maxim = new Maxim(this); player = maxim.loadFile("padperc.wav"); player.setLooping(true); player2 = maxim.loadFile("PadBass.wav"); player2.setLooping(true); buttonOn = false; buttonOn2 = false; } void draw(){ background(255); rect(0, 0, width/2, height/2); rect(width/2, height/2, width/2, height/2); fill(255); } void mousePressed() { if (mouseY < height/2) buttonOn = !buttonOn; if (buttonOn){ player.cue(0); player.play(); println("1"); } else { player.stop(); } if (mouseY < width/2) buttonOn2 = !buttonOn2; if (buttonOn2){ player2.cue(0); player2.play(); println("2"); } else { player2.stop(); } }
1