Hey, guys!
So, I’m still working on this quiz. Now my problem is that the music starts as soon as I open my Greenfoot project. I have an idea for a code to solve this problem. However, it doesn’t work at all. So, my plan is a Boolean which asks if the specific world is true. How do I solve my problem?
private GreenfootSound background = new GreenfootSound("background.mp3");
/**
* Constructor for objects of class MainMenu.
*
*/
public MainMenu()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1920, 1080, 1);
GreenfootImage bg = new GreenfootImage("london-background.png");
bg.scale(getWidth(), getHeight());
setBackground(bg);
mainMenu();
}
private void mainMenu() {
Logo logo = new Logo();
addObject(logo, 960, 540);
Greenfoot.playSound("background.mp3");
}
private void startMusic() {
background.playLoop();
}
private void stopMusic() {
background.stop();
}
private void backgroundMusic() {
if (World.MainMenu = true) {
startMusic();
} else {
stopMusic();
}
}
public void act() {
if(Greenfoot.isKeyDown("enter")) {
Greenfoot.playSound("mouse-click.mp3");
Greenfoot.setWorld(new playQuiz());
}
}
