Hello,
i have some music running in the background. It randomly picks one of 12 different soundfiles at the start of the game.
The code for the music and the game start (i have a title screen):
Now to the issue:
I wanted to make a method so that you can change the music by pressing "c", which looks like this:
The problem with this is that i can only change the music once. Is it possible to change the boolean after it picked the song? Or are there any other solutions?
Sorry for the long question and thanks for your help :).
static GreenfootSound BG; public static boolean enterPressed = false; static GreenfootSound GameMusic;
public void Music()
{
setBackground(Startscreen.getCurrentImage());
if (!enterPressed && Greenfoot.isKeyDown("enter"))
{
enterPressed = true;
if (GameMusic != null)
{
GameMusic.stop();
GameMusic = null;
}
else
{
GameMusic = new GreenfootSound("Musik"+(Greenfoot.getRandomNumber(11)+1)+".mp3");
GameMusic.playLoop();
GameMusic.setVolume(90);
Greenfoot.setWorld(new Spielfeld());
BG.stop();
}
}
else if (!Greenfoot.isKeyDown("enter"))enterPressed = false;
}static GreenfootSound newGameMusic; //I created newGameMusic because i couldnt figure out how to change GameMusic after it picked a songfile private boolean cDown;
public void changeMusic()
{
if (cDown != Greenfoot.isKeyDown("c"))
{
cDown =! cDown;
if (cDown)
{
Startscreen.GameMusic.stop();
newGameMusic = new GreenfootSound("Musik"+(Greenfoot.getRandomNumber(11)+1)+".mp3");
newGameMusic.stop();
newGameMusic.playLoop();
}
}
}
