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

2014/12/22

Level-up screen

abcd123 abcd123

2014/12/22

#
I want to make a level up screen, something among the lines of, if a persons clicks or presses a key it continues to the next level. I tried changing the background but the code didn't work. Any ideas? Heres the code:
 if(getWorld() instanceof level_1 && secs == 2){
            Greenfoot.stop();
            //if(Greenfoot.mouseClicked()){
            //       Greenfoot.setWorld(new level_2());
            //  }
        }
            
        if(getWorld() instanceof level_2 && secs == 3){
            Greenfoot.stop();
            
            Greenfoot.setWorld(new level_3());
        }
        
        if(getWorld() instanceof level_3 && secs == 4){
            Greenfoot.stop();
            
        }
Super_Hippo Super_Hippo

2014/12/22

#
If you call the 'stop' method, then it will stop and won't continue with the code after it.
abcd123 abcd123

2014/12/22

#
Is there an alternative?
danpost danpost

2014/12/22

#
Mouse clicks cannot be picked up during method execution, even if repeatedly checked on (they are picked up between act cycles and the state at that time is returned in the method calls); however, keyboard input can be received during method execution if repeatedly checked on. Try:
while (Greenfoot.getKey() == null) ; // nop (wait for keystroke)
Greenfoot.setWorld(new level_2());
davmac davmac

2014/12/22

#
If you call the 'stop' method, then it will stop and won't continue with the code after it.
This isn't correct; the 'stop' method halts the simulation loop after the current cycle has finished. It doesn't prevent code that immediately follows it from executing.
You need to login to post a reply.