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? :)


1 2 3 4 5 | oldX=Object.getx(); oldY=Object.gety(); removeObject(Object); //condition to add object again add Object(Object,oldX,oldY); |
1 2 3 4 5 6 7 8 9 10 11 12 | 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; } |
1 2 3 4 5 6 7 8 9 10 11 12 | // 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); |