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

2012/10/10

Help please

Stephon231 Stephon231

2012/10/10

#
how can you make it so that when an actor gets to a place in the world it goes to the next world
danpost danpost

2012/10/10

#
In the class of the actor in question.
// variables defining the area where the actor must be to switch worlds
int hitboxMinX, hitboxMaxX, hitboxMinY, hitboxMaxY;
// code to change worlds (after the movement code)
if (getX() >= hitboxMinX && getX() <= hitboxMaxX &&
    getY() >= hitboxMinY && getY() <= hitboxMaxY)
        Greenfoot.setWorld(new World2());
where 'World2' is the name of the world you wish to go to. Another way is to create a Hitbox actor; a transparent object that only checks for the actor to get there and change the world when it does.
Upupzealot Upupzealot

2012/10/10

#
And you'd better remember to add the actor to the new world, after the new world was created, before the “setWorld(World)”method :)
Builderboy2005 Builderboy2005

2012/10/10

#
You can actually do it after the setWorld() method too, as long as you do it before the Act cycle finishes.
Upupzealot Upupzealot

2012/10/10

#
@Builderboy2005 OK, you win :D
You need to login to post a reply.