I got this class
but when you play the game i would like to stop the sound that actually plays. how can i access to the currently playing sound?
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 27 28 29 30 31 32 33 34 35 36 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class son here. * * @author (your name) * @version (a version number or a date) */ public class son extends menu { private GreenfootImage sonOn; private GreenfootImage sonOff; private boolean Off = true ; public GreenfootSound sound = new GreenfootSound( "cliff.mp3" ); public son() { sonOn = new GreenfootImage( "son1.png" ); sonOff = new GreenfootImage( "son2.png" ); } public void act() { if ( Greenfoot.mouseClicked( this ) && Off) { setImage(sonOn); Greenfoot.delay( 50 ); sound.playLoop(); Off = false ; } else if ( Greenfoot.mouseClicked( this ) && !Off) { setImage(sonOff); sound.pause(); Off = true ; } } } |