I know about adding anobject and removing one, but I want an object to be added at the same position it was removed. How do I go about doing this? :)


oldX=Object.getx(); oldY=Object.gety(); removeObject(Object); //condition to add object again add Object(Object,oldX,oldY);
public void readdObject() { //saving the old objects coordinates in this integer variables; int objectsX; int objectsY; //the part where you find the object; Actor actor = getOneObjectAtOffset(Actor.class, 0, 0); //could also be other classes or methods you are using now. Just leave yours; //give the values of the objects coordinates to the variables objectsX and objectsY; objectsX = actor.getX(); objectsY = actor.getY(); getWorld().removeObject(actor);//remove the actor; getWorld().addObject(new Actor(), objectsX, objectsY);//add the new Actor. Probably Actor is the wrong type. Just add the type you want; }
// world class variables (or fields) SneakLeft sneakleft; // to hold the object int sneakleftX, sneakleftY; // to hold the removal location of the object // when creating SneakLeft object (in constructor of world) sneakleft = new SneakLeft(); addObject(sneakleft, whateverX, whateverY); // when removing 'sneakleft' sneakleftX = sneakleft.getX(); sneakleftY = sneakleft.getY(); removeObject(sneakleft); // when re-adding 'sneakleft' addObject(sneakleft, sneakleftX, sneakleftY);