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

2014/3/16

Adding an object back to the world after it is removed

patrick26 patrick26

2014/3/16

#
Hi, Is there a way to return an object back to the world after it has been removed? What is the code for this and do I insert the code into the World class or Actor class?
davmac davmac

2014/3/16

#
Yes, this is trivial. You just need to retain a reference to the object (eg. in a variable) and then use the standard addObject(...) method to add it back to the world. You can do it from a world or actor class (if from an actor, you use getWorld().addObject(...), of course).
1
2
3
Actor actor = ... ; // whatever you need to find the actor
getWorld().removeObject(actor); // remove actor
getWorld().addObject(actor, x, y); // add it back in (you must supply x and y).
You need to login to post a reply.