My game is almost finished. This one thing is driving me crazy! I have a world subclass called Menu that is a title screen. When the game runs it displays an image and you press space to start (which switches it to the other world subclass called MyWorld (the actual game)). Sometimes it works perfectly. But about 3/4 of the time, when you press the space bar, nothing happens. On Greenfoot, the little loading symbol appears. If you try to reset, a message comes up that says "Execution is taking a long time. You may need to terminate execution using the spinning button, below right." So I have to terminate it and try it a few more times until it works. I have no clue what is causing this.
Here is my menu subclass if it helps. It's very simple and only starts the music, displays the image, and (usually) switches to the game world when the space key is pressed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public class Menu extends World { public Menu() { super ( 600 , 400 , 1 ); } public static GreenfootSound backgroundMusic = new GreenfootSound( "nyanmusic.mp3" ); public void started(){ backgroundMusic.playLoop(); } public void act(){ if (Greenfoot.isKeyDown( "space" )) { Greenfoot.setWorld( new MyWorld()); } } } |