Hi, I have a piece of code that is misbehaving and I do not know why. So here is what I expect it to do; I except it to pause after I move from level 2 to level 3. But instead it just continues playing on, as well as starting a new instance of that song. So here is the code for the so called button of mine that causes the problems.
If there is any other code you need in order to understand a bit more about my game please let me know.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Music here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Music extends Actor
{
public GreenfootSound myMusic = new GreenfootSound("backGroundMusic.mp3");
boolean firstTurn = true;
/**
* Act - do whatever the Music wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(firstTurn)
{
myMusic.playLoop();
firstTurn= false;
}
if(Greenfoot.mouseClicked(this))
{
if(myMusic.isPlaying())
{
myMusic.pause();
setImage("play.png");
} else
{
myMusic.playLoop();
setImage("pause.png");
}
}
}
}
