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

2018/3/8

Continue

doglover555 doglover555

2018/3/8

#
If I have a pause button in my game and pressing it takes you to the "Pause menu" (a different world), is there a simple way to make the game continue from where it left off back in the Game world? Thanks.
danpost danpost

2018/3/8

#
Yes. Just pass a reference of the game world to the pause world when you create the pause world. Have the pause world hold it in a field. Then have the pause world set that referenced world active when needed.
Yehuda Yehuda

2018/3/8

#
You can return to the same instance of GameWorld.
// In PauseWorld
private World gameWorld;

public PauseWorld(World world) {
    gameWorld = world;
}

// in GameWorld when switching to PauseWorld
Greenfoot.setWorld(new PauseWorld(this));

// in PauseWorld when switching back
Greenfoot.setWorld(gameWorld);
I started before there were any replies.
doglover555 doglover555

2018/3/8

#
Yehuda wrote...
You can return to the same instance of GameWorld.
// In PauseWorld
private World gameWorld;

public PauseWorld(World world) {
    gameWorld = world;
}

// in GameWorld when switching to PauseWorld
Greenfoot.setWorld(new PauseWorld(this));

// in PauseWorld when switching back
Greenfoot.setWorld(gameWorld);
I started before there were any replies.
I had a "Pause" subclass under actor where I was saying something like:
if (Greenfoot.isKeyDown("q"))
        {
            Greenfoot.setWorld(new PauseMenu());
        }
so I'm not really sure how I could pass a world as the parameter and carry it over to the Pause subclass.
danpost danpost

2018/3/8

#
Change your line 3 to:
Greenfoot.setWorld(new PauseMenu(getWorld()));
and change PauseMenu as @Yehuda suggested.
You need to login to post a reply.