Hi, everyone! Well, i'm creating a game with several musics and scenarios, and i would like to know how i add musics in my worlds, for example: menu world. And stop the menu music when the game start or when credits button is pressed and the world changes to credit screen. I have a problem with that. Because i put the songs in the buttons of each scenario, so... in worlds with two or more button, when i press a button differently that the button with the method to play and stop the song, the music don't stop, and when a press to back to the menu, start two songs. Well, as you all can see, i need some help.
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 | public class Menu extends World { //Here is my menu code, without methods to play songs GifImage background = new GifImage( "GifMenuOriginal.gif" ); public void act() { setBackground( background.getCurrentImage() ); } public Menu() //Define as especificações de dimensão do mundo "Menu". { super ( 672 , 312 , 1 ); preparar(); } public void preparar() //Realiza as ações da classe, como add objetos. { addObject( new CapaMenu(), 544 , 156 ); //Adiciona a capa de "Menu" addObject( new Start(), 544 , 155 ); //Adiciona o botão de "Start" addObject( new Creditos(), 544 , 230 ); //Adiciona o botão de "Creditos" } } |
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 | public class Start extends Botao //Inicia o jogo { //Here is my start button code, i put the method GreenfootSound here, but the problem is: when pressed other button, like credits, sound don't stop GreenfootSound mainMusic = new GreenfootSound( "hometheme.mp3" ); public void act() { checarMouse(); checkS(); } public void checkS() { if (Greenfoot.mouseClicked( this )){ checarMouse(); checkClick( new Fase1()); mainMusic.stop(); } else { mainMusic.play(); } } } |