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

2016/6/23

Replacement

MrPancakes MrPancakes

2016/6/23

#
I'm making a fake Pokemon and I'm stuck with something. My character can get into the pokecenter and out fo the center. But if you get out of it, you spawn back at the beginning. I want it to be spawned at the front door of the center. Can you help me? I'm using an actor to place it back in the gameworld. Here is the code.
public void act() 
    {
        if (isTouching(Ash.class))
        {
            Greenfoot.setWorld(new MyWorld());
        }
    }
danpost danpost

2016/6/23

#
Have the actor save the game world object so you can set that one active again. When resetting it active, make sure to relocate the actor so that it does not instantly reactivate the pokecenter world again.
MrPancakes MrPancakes

2016/6/23

#
can you maybe put that in code or is that very difficult?
danpost danpost

2016/6/23

#
MrPancakes wrote...
can you maybe put that in code or is that very difficult?
It is not difficult:
/** in character class */
// instance field
World gameWorld;

// when going to Pokecenter
gameWorld = getWorld();
PokeCenter pc = new PokeCenter();
Greenfoot.setWorld(pc);
pc.addObject(this, 50, 50); // wherever

// when leaving Pokecenter
Greenfoot.setWorld(gameWorld);
gameWorld.addObject(this, 550, 200); // wherever
You need to login to post a reply.