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

2018/2/13

Return to a specific world

Maus2525 Maus2525

2018/2/13

#
I have tried to switch worlds using the following instruction:
import greenfoot.*;

public class Previous extends Actor
{    
    public void act() 
    {
        if (Greenfoot.mouseClicked(this) == true)
            Greenfoot.setWorld(new MyWorld());
    }    
}
but when I do the same thing to a world which is a subclass of a created world, it does not happen anything. Can you help me?
Vercility Vercility

2018/2/13

#
Show all relevant code sections
Maus2525 Maus2525

2018/2/14

#
That's all the code! I've created a few subclasses, which I've named MyWorld, Milky_Way_World (subclasses of World) and MW_World (which is a subclass of the Milky_Way World). I placed a "Previous" button (when is clicked, it should change the world to the initial world which I called MyWorld) in the MW_World and nothing happens, even though there are no syntax errors.
Super_Hippo Super_Hippo

2018/2/14

#
Does the 'Previous' class have a default image with a size big enough to click it? And is nothing in front of it? In any way, if you want to return to a 'specific world instance' and not to a new instance of that world class, you need to save a reference to the other world and change to that world instead of using 'new'. In your case, maybe nothing seems to happen because you are in MyWorld right now and set a new MyWorld active with no visible difference.
Maus2525 Maus2525

2018/2/14

#
Okay, thanks!
You need to login to post a reply.