This site requires JavaScript, please enable it in your browser!
Greenfoot back
Prish950
Prish950 wrote ...

2013/2/24

SOUND AT BACKGROUND PLEASE HELP!!!!

Prish950 Prish950

2013/2/24

#
I want that while you are playing the Mario theme is in the background but we wrote it so and it start the theme many timees ant once but i want just one theme that is going to loop. Thanks for helping!!
public void act()
    {
            if (!Greenfoot.isKeyDown("l"))
            {
                Greenfoot.playSound("MarioThemeAcapella.mp3");
            }    
} 
Gevater_Tod4711 Gevater_Tod4711

2013/2/24

#
Well if you want your sound to play in a loop the easyest way would be to use the playLoop mehtod of the GreenfootSound API. You just have to add some code like the following to your world constructor:
//in your world constructor;
GreenfootSound loopSound = new GreenfootSound("MarioThemeAcapella.mp3");
loopSound.playLoop();
Prish950 Prish950

2013/2/24

#
THANK YOU SO MUCH!! IS IT POSSIBLE TO PAUSE THE MUSICH IF THE RUN BOTTOM IS NOT SELECTED
Gevater_Tod4711 Gevater_Tod4711

2013/2/24

#
Do you want the music to start when the game starts or also to stop it the game is stoped? To start the music when the game is started you just need to get the code I posted before out of the constructor and into the method public void started because this one is called when the run button is pressed. If you also want the game to stop if the game is paused you need to change the code a bit:
public class Worldsubclass ... {

//here you need a global declaration of the sound;
private GreenfootSound loopSound = new GreenfootSound("MarioThemeAcapella.mp3");

public void started() {
    loopSound.playLoop();
}

public void stoped() {
    loop.pause();
}

}
Prish950 Prish950

2013/2/24

#
Thank YOU :D
You need to login to post a reply.