How do i make the scenario play sound if the user clicks on a particular button


1 2 3 4 5 6 7 8 9 | Actor button = new Actor() { public void act() { if (Greenfoot.mouseClicked( this )) ( new GreenfootSound( /* sound filename */ )).play(); } }; button.setImage( new GreenfootImage( /* image filename */ )); addObject(button, /* x, y locations */ ); |
1 2 3 4 5 6 7 8 9 10 11 12 | public void act() { if (Greenfoot.mouseClicked( this )) {( new GreenfootSound( "Star_Wars_Theme_Song.mp3" )).play(); getWorld().addObject( new SoundOn() , 909 , 62 ); } SoundOn.setImage( new GreenfootImage( "SoundOff.png" )); }} |
1 2 3 4 5 | if (Greenfoot.mouseClicked( this )) { ( new GreenfootSound( "SW.mp3" )).play(); setImage( "SoundOn.png" ); } |