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

2013/11/21

Multiple Worlds

alagon alagon

2013/11/21

#
How would i stop a program from running 2 worlds at once? After my world hits its game over....i initiate the world again, which means that there are 2 worlds running. How would i remove one of them? (Preferably through an actor class)
davmac davmac

2013/11/21

#
There's only ever one active world, and this is the only one that is "running" in the sense that its act method (and the act method of actors inside it) is called while the scenario runs. So normally you don't need to do anything special to prevent old worlds from running.
alagon alagon

2013/11/22

#
Ok...then...another question. How would i stop music from playing twice in a world?
davmac davmac

2013/11/22

#
So, is your problem that you change to a new world but the music from the original world keeps playing?
alagon alagon

2013/11/24

#
Yes...and it keeps stacking up...
davmac davmac

2013/11/24

#
Right. I'm not trying to be mean, but you would have had a much quicker solution to your problem if you had taken the time to explain it properly in the first place! You need to stop the music by calling GreenfootSound's stop() method on it before you switch to the new world. I can't tell you exactly how to do this unless you post your world code.
alagon alagon

2013/11/26

#
if(!backgroundMusic.isPlaying())
        {
            backgroundMusic.play();
        }
This is what i use in the world class. If I re-initialize the world, it plays twice. How would I stop this from playing twice?
davmac davmac

2013/11/27

#
As I said, you need to call the stop method (i.e. backgroundMusic.stop()) before you switch to the new world.
alagon alagon

2013/11/28

#
GreenfootSound backgroundMusic = new GreenfootSound("Theme.mp3"); 
public void act() 
    {
       if (Greenfoot.isKeyDown("y"))
       {
           backgroundMusic.stop();
           Greenfoot.setWorld(new Level1());
       }
       if (Greenfoot.isKeyDown("n"))
       {
           backgroundMusic.stop();
            Greenfoot.setWorld(new Menu());    
       }
    }
}
The music still won't stop playing. This is my actor class that use for stopping the music.
danpost danpost

2013/11/28

#
If you create and start the background music in your subclass of World, then you need to use a reference to that instance of GreenfootSound; not create a new one.
You need to login to post a reply.