I would like to stop the sound from playing when it gets to Gamover(game over), but it wont stop. Here's the code for Level1 (World) and Gamover(game over)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Level1 here. * * @author (your name) * @version (a version number or a date) */ public class Level1 extends World { GreenfootSound myMusic = new GreenfootSound("Dragon Ball Z Budokai 3 Opening Theme _Full Version_ _HQ_ U.S Version.mp3"); Scoreboard counter = new Scoreboard(); /** * Constructor for objects of class Level1. * */ public Level1() { super(600, 400, 1); Beginning aworld = new Beginning(); Greenfoot.setWorld(aworld); } public Level1(boolean second) { super(600, 400, 1); addObject(new Player(), 200,200); addObject(counter, 100, 40); } public Scoreboard getScoreboard() { return counter; } public void act() { if(Greenfoot.getRandomNumber(1000) <20) { Enemy e = new Enemy(); addObject (e, Greenfoot.getRandomNumber(getWidth()-20)+10, -30); } myMusic.playLoop(); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Gamover here. * * @author (your name) * @version (a version number or a date) */ public class Gamover extends World { GreenfootSound myMusic = new GreenfootSound("Dragon Ball Z Budokai 3 Opening Theme _Full Version_ _HQ_ U.S Version.mp3"); /** /** * Constructor for objects of class Gamover. * */ public Gamover() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); if(myMusic.isPlaying()) { myMusic.stop(); } } public void act() { myMusic.stop(); if (Greenfoot.mouseClicked(this)) { Beginning aworld = new Beginning(); Greenfoot.setWorld(aworld); } } }