(I feel so ashamed for needing to ask so many questions here, and not being able to help other people, but once again I need your help)
I'm trying to add a pause button to my game. I've coded so when the image used is the "pause button" the game is running, and I would like to make so when the "play icon" is being used all the actors that are subclasses of SmoothMover() stop acting. I thought of doing something like this:
Game class (subclass of World):
Pause button (subclass of Actor):
But it doesn't work (the IllegalMonitorStateException is catch directly when I press run). Can anyone help me achieve this, please?
/**
* Will pause the game, stopping all actors from moving and will show Main Menu and Replay option
*/
public void pauseGame()
{
addObject(new Replay(), WIDE/4 , HIGH/2);
addObject(new Replay(), WIDE/4 * 3, HIGH/2);
try
{
getObjects(SmoothMover.class).notifyAll();
} catch(IllegalMonitorStateException e)
{
System.out.println("Error with SmoothMover class: " + e.getMessage());
System.exit(-1);
}
}
/**
* Will resume the game, if there was a pause menu before,
* Panels will be removed and the actors will be awaken
*/
public void resumeGame()
{
removeObjects(getObjects(Panels.class));
try
{
getObjects(SmoothMover.class).wait();
} catch(InterruptedException e)
{
System.out.println("Error with SmoothMover class: " + e.getMessage());
System.exit(-1);
}
} public void act()
{
if(this.getImage() == images[0])
{
((Game) getWorld()).resumeGame(); //resumes the game
} else {
((Game) getWorld()).pauseGame(); //pauses the game
}
}
