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

1 2 3 4 5 6 7 8 9 10 11 | public class SoundPlay extends Actor { public GreenfootSound backgroundMusic = new GreenfootSound( "K-Hole.mp3" ); public boolean soundPlaying = false ; public void act() { } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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 ; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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 ; } |