This site requires JavaScript, please enable it in your browser!
Greenfoot back
RobiJefferson
RobiJefferson wrote ...

2013/5/30

Paused Game

RobiJefferson RobiJefferson

2013/5/30

#
is there any which can help me? how the script to pause the game? Thank you
Gevater_Tod4711 Gevater_Tod4711

2013/5/30

#
That depends on what you mean by pause the game. If you just want the game to stop you can use Greenfoot.stop(). But then the player can only continue the game using the run button. Another method would be to use a break menu (a menu that comes up when the game should be paused where you can change the settings or continue the game like in many games). But this wouldn't be so easy. Therefore you have to check if there is an instance of a break menu in every class you have. If you want to do it this way the easyest way would be:
public void act() {
    if (getWorld().getObjects(BreakMenu.class).isEmpty()) {//BreakMenu.class has to be the classname of the menu; change this if your menu is named different;
        run();
    }
}

public void run() {
    //this method is your current act method;
    //you just have to change the name of your current act method to run (because you got the new act method that calles the run method if there is no break menu);
}
You have to change all classes you have this way with the exception of the break menu and the world class.
RobiJefferson RobiJefferson

2013/5/30

#
what do you mean in the world class? then script what is in use in class BreakMenu?
Gevater_Tod4711 Gevater_Tod4711

2013/5/30

#
In the world class (the subclass of greenfoot.World) there should be no such change I think because this menu should be called by the worldclass. To add this menu to the world you can use this in your world class:
public void act() {
    if (Greenfoot.isKeyDown("esc") && getObjects(BreakMenu.class).isEmpty()) {
        addObject(new BreakMenu(), getWidth()/2, getHeight()/2);
    }
    //may some other stuff.
}
The break menu is just a menu class. You should have a button to remove the menu and maybe to change some settings.
RobiJefferson RobiJefferson

2013/5/30

#
thank you, i will try it
You need to login to post a reply.