So I’ve programmed my game using the .fisica and processing sound library. I’ve created a menu screen and game screen. I want there to be one song that plays for the menu, and another one that plays for game. But, whenever I try to move the audio files into the correct function, it glitches out with static.
Is it possible to set up an “if or else statement” or boolean for the two songs to play in the separate fuctions correctly?
import processing.sound.*;
import fisica.*;
FWorld world;
//backdrops
int gameScreen = 0;
int score =0;
PImage gamestartup;
PImage forest;
**SoundFile file;**
**String startupsong = "startupmusic.mp3";**
**String path;**
**//String gamemusic ="gamemusic.mp3"**
**//start_song play1;**
**//game_song play 2;**
FCircle fc_owl;
FCircle fc_rat;
FCircle fc_rat2;
Timer startTimer;
void setup()
{
size(800, 600);
Fisica.init(this);
Fisica.setScale(10);
**file = new SoundFile(this, "startupmusic.mp3");**
** file.play();**
}
void draw() {
if (gameScreen== 0) {
intitScreen();
} else if (gameScreen == 1) {
gameScreen();
world.step();
if (fc_owl.isTouchingBody(fc_rat))
{
fc_rat.setPosition(random(20, width-20), 475);
fc_owl.setPosition(400, 69);
fc_owl.setStaticBody(false);
score = score+10;
} else if (fc_owl.isTouchingBody(fc_rat2))
{
fc_rat2.setPosition(random(20, width+20), 475);
fc_owl.setPosition(200, 169);
fc_owl.setStaticBody(false);
score = score+10;
}
world.draw();
}
}
void intitScreen() {
gamestartup = loadImage("gamestartup-HH.png");
background(32, 55, 150);
rect(105, 0, 600, 600);
fill(255);
image(gamestartup, 110, 5);
PFont f= createFont("Georgia", 64);
String s = "Click to Play";
textFont(f);
textAlign(CENTER);
textSize(64);
text(s, 410, 550);
}
void gameScreen() {
background(0);
forest = loadImage("forest-and-trees-at-night-in-the-darkness-edit.png");
image(forest, 0, 0);
PFont f= createFont("Georgia", 64);
String s = "Score = " + score;
textFont(f);
fill(255);
textAlign(CENTER);
textSize(30);
text(s, 650, 50);
println(millis());
startTimer.countUp();
text(startTimer.getTime(),200,50);