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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 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(); } } |