Hi there,
I'd like to create a button which turns music on and off.
How do I do this? I already created images for the "pause" and "play" button...


1 2 3 4 5 6 7 | import greenfoot.*; public class Buttons extends Actor { GreenfootSound backroundMusic = new GreenfootSound( "SpongebobRemix.mp3" ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import greenfoot.*; public class MusicON extends Buttons { public void act() { if (Greenfoot.mouseClicked( this )) { backroundMusic.playLoop(); getWorld().addObject( new MusicOFF(), getX(), getY()); getWorld().removeObject( this ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import greenfoot.*; public class MusicOFF extends Buttons { public void act() { if (Greenfoot.mouseClicked( this )) { backroundMusic.pause(); getWorld().addObject( new MusicON(), getX(), getY()); getWorld().removeObject( this ); } } } |