I have been experiencing an issue whereby if I use 'Greenfoot.start();' to automatically start my scenario, when I reset the scenario, after going to a different world, the world will not completely initialize; or freeze upon completion of instantiation (like it gets caught in an infinite loop). Maybe someone on the Greenfoot team could look into this.
Or at least tell me what is wrong with the following.
Using two World sub-classes with the following code:
and
Run and click the window once or more. Then click the 'Reset' button to reproduce problem.
import greenfoot.*; import java.awt.Color; public class Main extends World { public Main() { super(400, 600, 1); GreenfootImage text = new GreenfootImage("Click mouse\nto go to\nthe next world", 64, Color.black, Color.white); GreenfootImage bg = getBackground(); bg.drawImage(text, (bg.getWidth()-text.getWidth())/2, (bg.getHeight()-text.getHeight())/2); Greenfoot.start(); } public void act() { if (Greenfoot.mouseClicked(null)) Greenfoot.setWorld(new Second()); } }
import greenfoot.*; import java.awt.Color; public class Second extends World { private static int count; public Second() { super(400, 600, 1); count++; GreenfootImage text = new GreenfootImage("Click mouse\nto restart\nthis world ("+count+")", 64, Color.black, Color.white); GreenfootImage bg = getBackground(); bg.drawImage(text, (bg.getWidth()-text.getWidth())/2, (bg.getHeight()-text.getHeight())/2); } public void act() { if (Greenfoot.mouseClicked(null)) Greenfoot.setWorld(new Second()); } }