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

2018/6/3

Scenario stopping when switching worlds

mulon mulon

2018/6/3

#
My code was working before when the argument of the if statement was based on where the mouse was, but now after I have changed it, the scenario stops when switching to a different world. What can I do to make the scenario not pause?
World cubbiesPic = new cubbies();
        if(Greenfoot.isKeyDown("shift") &&
            player.getX() >= 450 && player.getX() <= 550 && 
            player.getY() <= 250 && player.getY() >= 150)
        {
            Greenfoot.setWorld(cubbiesPic);
        }
danpost danpost

2018/6/3

#
mulon wrote...
My code was working before when the argument of the if statement was based on where the mouse was, but now after I have changed it, the scenario stops when switching to a different world. What can I do to make the scenario not pause? << Code Omitted >>
Nothing in the code given would be the cause of the scenario stopping. Must be something you changed elsewhere (or a bug in greenfoot, which I doubt in this case). If you are getting an error message, please show. If not, you probably have a Greenfoot.stop() command stopping the scenario. One improvement, however, would be to move line 1 inside the if block. Makes no sense to create a world and then ask if one should be created (also, this would happen continuously until the conditions where true, overburdening the CPU). You can simply remove line 1 and change line 6 to the following:
Greenfoot.setWorld(new cubbies());
You need to login to post a reply.