在状态下使用极小值播放声音

时间:2019-04-25 19:57:31

标签: processing minim

这是我的第一个处理项目,我在播放声音时遇到一些困难。我希望player1剪辑开始在stateMainScreen中循环播放,但我不知道如何获取它。

我的第二个问题是,我只希望单击圆圈时在stateMainScreen中播放player2声音。但是在stateStartScreen上,如果单击“输入”按钮的左上角(圆圈将在下一个屏幕上显示),将播放player2。有没有办法让我不玩,直到您已经进入stateMainScreen?

很抱歉,如果该帖子令人困惑。任何帮助表示赞赏!

我正在运行Processing 3.4。

到目前为止,这是我的代码:

import ddf.minim.*;
Minim minim;
AudioPlayer player1;
AudioPlayer player2;
AudioPlayer player3;
AudioInput input;

final int stateStartScreen = 0;
final int stateMainScreen = 1;
int state = stateStartScreen;

PImage img;
PFont font;

Button my_button;
int clk = 1;

Circle circle1;

void setup() {
  size(800, 600);
  my_button = new Button("Enter", 320, 320, 100, 50);
  circle1 = new Circle(320, 320, 40, 40);

  //String[] fontlist = PFont.list();
  //printArray(fontlist);

  font = createFont("Geneva", 14);
  textFont(font);
  img = loadImage("Start-Screen-Background.jpg");

  minim = new Minim(this);
  player1 = minim.loadFile("Cicadas.mp3");
  player2 = minim.loadFile("Rain.mp3");
  player3 = minim.loadFile("Starting-burner.mp3");
}

void draw() {
  switch(state){
    case stateStartScreen:
      showStartScreen();
      break;
    case stateMainScreen:
      showMainScreen();
      break;
  }
}

void showStartScreen(){
  background(img);
  my_button.Draw();
}

void showMainScreen(){
  background(34, 139, 34);
  //To see x & y coordinates on the screen (remove later)
  textSize(10);
  text("x:" + mouseX + "y:" + mouseY, 30, 10);
  textSize(32);
  text("Main", 255, 255, 255);
  circle1.Draw();
  //sound isn't playing
  player1.loop();
}

class Circle {
  float x;
  float y;
  float w;
  float h;

  Circle(float xpos, float ypos, float widthA, float heightA) {
    x = xpos;
    y = ypos;
    w = widthA;
    h = heightA;
  }

  void Draw() {
    fill(0);
    stroke(0);
    ellipse(x, y, w, h);
  }

  boolean overCircle() {
  if (mouseX >= 305 && mouseX < (305 + 40) &&
      mouseY >= 305 && mouseX < (305 + 40)) {
        return true;
      } else {
        return false;
      }
  }
}


class Button {
  String label;
  float x;
  float y;
  float w;
  float h;

  Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
    label = labelB;
    x = xpos;
    y = ypos;
    w = widthB;
    h = heightB;
  }

  void Draw() {
    fill(218);
    stroke(141);
    rect(x, y, w, h, 10);
    textAlign(CENTER, CENTER);
    fill(0);
    text(label, x + (w/2), y + (h/2));
  }

  boolean overButton() {
  if (mouseX >= x && mouseX < (x + w) &&
      mouseY >= y && mouseY < (y + h)) {
        return true;
      } else {
        return false;
      }
  }
}

void mousePressed(){
  if(my_button.overButton()){
    state = stateMainScreen;
  }
}

void mouseClicked(){
  if(state == stateMainScreen && circle1.overCircle() == true) {
    player3.rewind();
    player3.play();
  }

}

0 个答案:

没有答案