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

2016/3/5

changing world and adding a actor to it

Cameronte10 Cameronte10

2016/3/5

#
Im doing a thing where the play touches the house and the world will change to a smaller size and background. The problem is i don't know how to add the player into the new world. This is what i have:
public void act() 
    {
     Actor player;  
     player = getOneObjectAtOffset(0, 0, Player.class);
     if (player != null)
     {
       Greenfoot.setWorld(new inside());
       getWorld().addObject(player, 200, 50);

       
       
     }
Super_Hippo Super_Hippo

2016/3/5

#
First, the world name should start with an uppercase letter. Then it could look like this:
public void act()
{
    Actor player = getOneObjectAtOffset(0, 0, Player.class);
    if (player != null)
     {
        World inside = new Inside();
        inside.addObject(player, 200, 50);
        Greenfoot.setWorld(inside);
    }
}
Or, if you move the code to the Player class:
if (isTouching(House.class))
{
    World inside = new Inside();
    inside.addObject(this, 200, 50);
    Greenfoot.setWorld(inside);
}
Cameronte10 Cameronte10

2016/3/6

#
Thanks. Helped me a lot.
You need to login to post a reply.