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.
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)
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();