Hey there!
I have a little Problem.
I tried to make a main Menu, with a sound in the background. The actual game has got another sound in the background, so I need to stop the Main Menu theme when I start the game. The new_Game button starts the game, so I need to stop the Music, when this button is clicked. The problem is, that Greenfoot loads another world, when the Game starts. I tried to detect, when this button is pushed, so I could stop the music, but it just wont work.
import greenfoot.*; public class Main_menu extends World { //-----------DEFINE SOUNDS----------- GreenfootSound bgm2 = new GreenfootSound("wav1.mp3"); GreenfootSound bgm1 = new GreenfootSound("wav2.mp3"); //-----------DEFINE OBJECTS----------- checkWorld checkWorld = new checkWorld(); newgame newgame = new newgame(); Options Options = new Options(); Credits Credits = new Credits(); //-----------DEFINE dbb(DebugButton) and cli(Click detected - sign)----------- dbb dbb = new dbb(); cli cli = new cli(); //-----------SET CURRENT STATE----------- boolean Beta =true; public Main_menu() { super(1100, 700, 1); //add all main Menu buttons! addObject(newgame,550,250); addObject(Options,550,450); addObject(Credits,84,680); //add the Debug-button if Beta=true if(Beta==true) { addObject(dbb,997,636); } //currently disabled function if (worldChanges()==true) { if(Beta==true) { addObject(cli,900,636); } bgm1.stop(); Greenfoot.delay(30); } } public void started() { bgm1.play(); } public boolean worldChanges() { if (Greenfoot.mouseClicked("Options")==true) {return true;} if (Greenfoot.mouseClicked("Credits")==true) { Greenfoot.setWorld(new Cred()); return true;} if (Greenfoot.mouseClicked("cli")==true) {return true;} if (Greenfoot.mouseClicked("newgame")==true) { return true; } {return false;} } public void stopped() { bgm1.pause(); } }