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

2019/6/13

How can I respawn in the world I am currently in?

keyfive keyfive

2019/6/13

#
FirstDoor is in multiple worlds. I want it so that if Zee touches FirstDoor, it will set the world to whatever world the touched FirstDoor was in. This is the code for FirstDoor.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class FirstDoor here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class FirstDoor extends Actor
{
    World currentWorld = getWorld();
    /**
     * Act - do whatever the FirstDoor wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(isTouching(Zee.class)) {
           World currentWorld = getWorld();
           Greenfoot.setWorld(new currentWorld());
        }
    }    
}
Super_Hippo Super_Hippo

2019/6/13

#
If a Zee Actor touches a FirstDoor Actor, then both are in the same world at that time (otherwise they couldn't touch).
You need to login to post a reply.