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

2019/1/10

sound loop issue

qwe qwe

2019/1/10

#
I am trying to end the music on my start screen as soon as I switch worlds in my game. Normally, the music finishes an entire loop before stopping. I have an actor on my startscreen that when pressed, it will switch worlds to the game screen but I don't know how to stop the music right away.
public class StartScreen extends World
{

    /**
     * Constructor for objects of class StartScreen.
     * 
     */
    public StartScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        prepare();
        Greenfoot.playSound("Opening.wav");
    }
public class PlayButton extends Actor
{
    /**
     * Act - do whatever the PlayButton wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {    
        if(Greenfoot.mouseClicked(this))
        {
            Greenfoot.setWorld(new GameScreen()); 
        }
    }    
}
Zamoht Zamoht

2019/1/10

#
You should use an instance of GreenfootSound documented here then you can control when to play and stop the sound.
qwe qwe

2019/1/11

#
Iv'e tried that, but i keep on receiving errors. How else can I do it?
danpost danpost

2019/1/11

#
qwe wrote...
Iv'e tried that, but i keep on receiving errors. How else can I do it?
What errors are you getting? (copy/paste in entirety)
You need to login to post a reply.