How to reset a World while the Program is running? In my Game I want to give the user the option to reset the Level with just the press of the R button.
Greenfoot.setWorld(new MyWorld()); //with MyWorld being the class of the world you want to restart
// in superclass of the levels
public void act()
{
String key = Greenfoot.getKey();
if ("r".equals(key) || "R".equals(key)
{
resetWorld();
}
// other key detection codes here, if any
}
// to be overridden in each level subclass
protected void resetWorld() {}// in Level1 world, for example
protected void resetWorld()
{
Greenfoot.setWorld(new Level1());
}protected void resetWorld()
{
Greenfoot.setWorld(new MyWorld());
}super.resetWorld();