I have sounds that play with acts but how do i add background music?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import greenfoot.*; public class MyWorld extends World { GreenfootSound backgroundMusic = new GreenfootSound( "musicFilename.mp3" ); public MyWorld() { super ( 600 , 400 , 1 ); backgroundMusic.playLoop(); // etc. } // etc. } |
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 | // *** begin class header *** // import statement(s) import greenfoot.*; // class declaration statement public class MyWorld extends World // *** end class header *** // *** begin class code *** { // field declaration statement(s) GreenfootSound backgroundMusic = new GreenfootSound( "musicFilename.mp3" ); // *** begin instance object constructor(s) *** public MyWorld() { super ( 600 , 400 , 1 ); backgroundMusic.playLoop(); // etc. } // *** end instance object constructor(s) *** // *** begin method(s), if any *** // etc. // *** end method(s), if any *** } // *** end class code *** |
1 2 3 4 5 6 7 8 | public void stopped() { bg.setVolume( 0 ); //change bg to what you declared the file as } public void started() { bg.setVolume( 100 ); //change bg to what you declared the file as } |
1 2 3 4 5 6 7 8 9 | public void stopped() { bg.pause(); } public void started() { bg.playLoop(); } |