这是我所拥有的:
2 个按钮
2 个声音
当按下按钮 1 时,我想要播放声音 1 当按下按钮 2 时,我只想播放声音 2。
我的代码:
import ddf.minim.*;
RadioButtons r;
boolean showGUI = false;
Minim minim;
AudioPlayer player_1;
AudioPlayer player_2;
PImage img, img2;
PShape img1;
void setup() {
size(1024,735);
String[] radioNames = {"Button1", "Button2"};
r = new RadioButtons(radioNames.length, 20,700,50,30, HORIZONTAL);
r.setNames(radioNames);
img = loadImage("img.jpg");
img1 = loadImage("img1.png");
img2 = loadShape("img1.svg");
minim = new Minim(this);
//sound1
player_1 = minim.loadFile("sound1.wav");
//sound2
player_2 = minim.loadFile("soun2d2.wav");
}
void draw() {
//background(0);
//println (mouseX +"," + mouseY);
// Draw the image to the screen at coordinate (0,0)
//sound1
image(img,0,0);
if(r.get() == 0)
shape(img1,695,106);
if(mousePressed){
if(mouseX>695 && mouseX <695+190 && mouseY>106 && mouseY <106+180){
fill(0,0,0,0);
image(img2,300,150);
player_1.cue(0);
player_1.play();
}
}
//sound2
if(r.get() == 1)
shape(img1,695,106);
if(mousePressed){
if(mouseX>695 && mouseX <695+190 && mouseY>106 && mouseY <106+180){
fill(0,0,0,0);
image(img2,300,150);
player_2.cue(0);
player_2.play();
}
}
if(showGUI)
{
r.display();
}
}
void mouseReleased()
{
if(showGUI){
if(mouseY> height-60)
r.mouseReleased();
else
showGUI = false;
}
else{
showGUI = true;
}
}
此刻,两种声音同时播放。
我错过了什么?