Hi! I have developed a game for a school project and I have a question. In "MyWorld" class i start my background music as it shows
How can I make my sound stop from the actor's class? In particular from here.
public class MyWorld extends World { Start start = new Start(); Title title = new Title(); boolean isPaused = true; /** * Prepare the world for the start of the program and creates initial * objects. */ private void prepare() { addObject(start, getWidth()/2, 450); addObject(title, getWidth()/2, getHeight()/4); Greenfoot.start(); } public void act() { /** * Checks if the start icon has been pushed and then removes title * and icon and adds the car, the counter and starts the game */ if (Greenfoot.mouseClicked(start)) { Counter counter = new Counter(); addObject(counter, 50,50); RedCar redcar = new RedCar(counter); addObject(redcar,255,483); GreenfootSound music = new GreenfootSound ("Music.mp3"); music.playLoop(); isPaused = false; } } }
public void stopsRedCar() { if (canSee(GrayCar.class)||canSee(BlackCar.class)||canSee(Cone.class)) { Greenfoot.playSound("Crash.mp3"); GameOver gameOver = new GameOver(); getWorld().addObject(gameOver, 300, 300); Greenfoot.stop(); } }