I would like to know how i could start a backgroundsong if I get into the world and how to stop it when i press enter, could someone help me? I am a beginner in greenfoot, so I don't know how everything works yet. this is the code for the world, but the music keeps going:
import greenfoot.*;
public class Gehaald extends World
{
//(achtergrondmuziek toevoegen)
GreenfootSound backgroundMusic = new GreenfootSound("AcousticShuffle.wav");
//(manier toevoegen om naar het beginscherm terug te komen + grootte van de wereld)
public Gehaald()
{
//(grootte van de wereld + toevoegen van muziek)
super(1000, 700, 1);
backgroundMusic.playLoop();
}
public void act()
{
//(als er op enter wordt gedrukt, begin je weer bij het startmenu)
if (Greenfoot.isKeyDown("enter"))
{
Greenfoot.setWorld(new Startmenu());
}
}
//(muziek laten stoppen als je uit het level gaat)
public void stopped()
{
backgroundMusic.setVolume(0);
}
}

