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

2016/4/8

How do you check if an object is in the world?

thmysdar thmysdar

2016/4/8

#
How do you check if an object is in a world? Not if its null, not if its in a class (it's already initialized in the class) but physically in the world with an x and y coordinate
Super_Hippo Super_Hippo

2016/4/8

#
How can an object be "in a class"? I have the feeling that you didn't understand what a class and an object are.
danpost danpost

2016/4/8

#
The 'getWorld' method will return one of two things for an Actor object -- either the world the actor is in or 'null', if not in a world. So checking for 'null' will return a 'true' value if the actor is not in a world and checking for 'not null' will return 'true' if the actor is in a world:
1
if (getWorld() != null)
You need to login to post a reply.