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

2014/11/13

Changing worlds when reaching a certain score?

blueman08 blueman08

2014/11/13

#
I'm trying to make it so that when my counter reaches a certain score in my game it changes to the other world I have while retaining the same score from before and continuing the game. How would I go about doing this?
JDSmooth JDSmooth

2014/11/13

#
You can just write another method with an if statement. If counter == (num) then Greenfoot.setWorld(whatever world.) I think that should work.
danpost danpost

2014/11/13

#
You can pass a reference to the old world to the other world and just set that world active later:
private World gotoWorld;

public OtherWorld(World lastWorld)
{
    gotoWorld = lastWorld;
    // etc.
}

public void act()
{
    // whatever
    if (some condition) Greenfoot.setWorld(gotoWorld);
}
Setting up your 'other world' with the instance field to hold the first world, you can then pass the reference with
if (score >= value) Greenfoot.setWorld(OtherWorld(getWorld());
and save the reference (constructor) until needed (act).
You need to login to post a reply.