Hi,
I am trying to create a sound control. ( ON and OFF ) only.
would should happen is:
If I click on the image it should change the image and start or stop the sound.
But it is not working as expected, the stop doesn't work at all , and the sound repeat it self if I click start again.
Anybody out there that could help me ?
See the code below
public class SoundPlay extends Actor
{
public GreenfootSound backgroundMusic = new GreenfootSound("K-Hole.mp3");
public boolean soundPlaying = false;
public void act()
{
}
}
public class Sound_ON extends SoundPlay
{
public void act()
{
if(Greenfoot.mouseClicked(this)|| Greenfoot.isKeyDown("x"))
{
turnOFF();
}
}
public void turnOFF()
{
Sound_OFF sound_off = new Sound_OFF();
getWorld().addObject(sound_off , 1042, 561);
getWorld().removeObject(this);
backgroundMusic.stop();
soundPlaying=false;
}
}public class Sound_OFF extends SoundPlay
{
public void act()
{
if(Greenfoot.mouseClicked(this)|| Greenfoot.isKeyDown("z"))
{
turnON();
}
}
public void turnON()
{
Sound_ON sound_on = new Sound_ON();
getWorld().addObject(sound_on , 1042, 561);
getWorld().removeObject(this);
backgroundMusic.play();
soundPlaying=true;
}


