i've watched the greenfoot tutorial on youtube to play and stop the music. but it was just possible in one class. How do i control the music from Worldy class to StartScreen class? i need to play different music in different world.
here is the code.
Worldy class:
StartScreen class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Worldy extends World
{
GreenfootSound bgsound = new GreenfootSound("Backsound.mp3");
HealthBar healthbar = new HealthBar();
HealthBarAI healthbarai = new HealthBarAI();
public Worldy()
{
super(900, 600, 1);
setBackground("City.png");
addObject(new Ground(900, 60), 450, 600);
addObject(new Ground(200, 60), 300, 420);
addObject(new Ground(400, 60), 700, 300);
addObject(healthbar,700,125);
addObject(healthbarai,200,125);
menuSound.stop(); //<- stop the menusound when in game.
bgsound.playLoop();
PlayerBot player = new PlayerBot();
addObject(player, 450, 525);
addObject(new EnemyBot(), 200, 525);
}
public HealthBar getHealthBar()
{
return healthbar;
}
public HealthBarAI getHealthBarAI()
{
return healthbarai;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class StartScreen extends World
{
GreenfootSound menuSound = new GreenfootSound("Menusound.mp3");
public StartScreen()
{
super(900, 600, 1);
prepare();
bgsound.stop(); //<- stop the backsound music when in menu.
menuSound.play();
}
private void prepare()
{
TitleMulai titlemulai = new TitleMulai();
addObject(titlemulai,769,408);
TitleBantuan titlebantuan = new TitleBantuan();
addObject(titlebantuan,726,512);
}
}

