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

2018/3/5

How to check if a player is in a world?

sadiebean00 sadiebean00

2018/3/5

#
Hi everyone, I was wondering if there is any code like the isTouching method to see if your player is in the world that you are currently in. This would help with my game that I am creating. An example would be if (player is in == level 1) { execute code} else if (player is in == level 2) {execute code} else if (player is in == level 3) {execute code} Hope this helps. Thank you.
CubeGamer6 CubeGamer6

2018/3/5

#
You could do something like
if(getWorld().getClass() == level1.class) {
    // do stuff
}
If you get nullpointerexceptions just add "getWorld() != null && " to the start of the if statement
sadiebean00 sadiebean00

2018/3/5

#
Thank you this works :)
You need to login to post a reply.