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?
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 | 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()); } } |