This is my code, I want the class to play through the wasted sound once, and then once it has finished playing play the gameOverBGM sound in a loop. However, the if statements condition is never met and the gameOverBGM line is never reached. I can't just input wasted.stop() after wasted.play otherwise the sound will not play through once and it will immediately play my gameOverBGM. need some advice, thanks.
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 | public class GameOverWorld extends World { static GreenfootSound wasted = new GreenfootSound( "Wasted.mp3" ); static GreenfootSound gameOverBGM = new GreenfootSound( "EndGameMusic.mp3" ); public GameOverWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1200 , 675 , 1 ); prepare(); wasted.play(); if (!wasted.isPlaying()){ gameOverBGM.playLoop(); } } void prepare(){ addObject( new BackToMenu(), 315 , 450 ); addObject( new MenuIndicator(), 250 , 200 ); } public void act(){ if (getObjects(GameOver. class ).isEmpty()) showGameOver(); return ; } private void showGameOver() { addObject( new GameOver(), getWidth() / 2 , getHeight() / 2 ); } public static GreenfootSound getMusic(){ return gameOverBGM; } } |