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

2014/2/23

Music not playing

Trxnce Trxnce

2014/2/23

#
help after al my previous problems my music wont play, this is my code
private GreenfootSound bgmusic = new GreenfootSound("BGMusic.mp3");  
     public void started()  
{  
    bgmusic.playLoop();  
}  
  
public void stopped()  
{  
    bgmusic.stop();  
}
danpost danpost

2014/2/23

#
The 'started' and 'stopped' methods will only be executed if the world class that the code is in is active when the project itself is started or stopped (not when the world object becomes active or inactive). If your initial world is not of this class that the 'started' method is in, it will not be executed.
Trxnce Trxnce

2014/2/23

#
is there a way for me to do it because when the game starts it makes a menu but i dont want the music to play on the menu only after they have pressed play and the game world has loaded
danpost danpost

2014/2/23

#
You can either put the code in the Menu world and start the music at the time you set the Game world active; or, you can start put the code in the Game world and start it in its constructor.
Trxnce Trxnce

2014/2/23

#
how do i start it in its constructor, can you give me an example please
danpost danpost

2014/2/23

#
It would be something like the following:
public class WorldClassName extends World
{
    private GreenfootSound bgmusic = new GreenfootSound("BGMusic.mp3");

    public WorldClassName()
    {
        super(/* size of world */);
        bgmusic.playLoop();
        // etc.
    }
    // etc.
}
You need to login to post a reply.