Hi there! This is my first Processing project and I’m having some difficulty with the sounds playing when I want them to. I want the player1 clip to start looping in the stateMainScreen but I can’t figure out how to get it to do that.
My second problem is that I only want the player2 sound to play in the stateMainScreen when the circle is clicked. But on the stateStartScreen, if you click in the top left corner of the “enter” button (where the circle will be on the next screen), player2 will play. Is there a way I can get it to not play until you are already on the stateMainScreen?
Sorry if this post is confusing. Any help is appreciated!
Here is my code so far:
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();
}
}