Original Position Messing up

Hi,

I want to try a simple task where if i move a object inside the world and then press a button it should go back to its original position , but its not working , below is the code i am using - the file is here - http://www.fastswf.com/yAnIvBs (when i remove the event listener)

with event listener - http://www.fastswf.com/rpYsIt8

////////========================
stop();

var startXPos:Number = level1WorldObj.box1.x;
var startYPos:Number = level1WorldObj.box1.y;

function areaS(e:Event) {



level1WorldObj.box1.y= startYPos;
level1WorldObj.box1.x= startXPos;
level1WorldObj.box1.removeEventListener(Event.ENTER_FRAME, areaS);


}

but1.addEventListener(MouseEvent.CLICK,nClick3);

function nClick3(event:MouseEvent):void{
level1WorldObj.box1.addEventListener(Event.ENTER_FRAME, areaS);
level1WorldObj.box1.y= startYPos;
level1WorldObj.box1.x= startXPos;
}

/////////////////======================


Now i want to be able to do it many time so i kept the variables that detect the initial x, y as global ...

Also if i remove this eventlistener-

level1WorldObj.box1.removeEventListener(Event.ENTER_FRAME, areaS);

the box does go back to original position but then does not move at all ....

can you please guide me ....

Regards
Jin
Hi ,

I have tried adding the rotation angle also but that does not seem to work as well 🙁 , any suggestions ...

A most strange behavior seems to be happening the movie clip seems to move but not the body , please see this in debugdraw - http://www.fastswf.com/-Ijkta4

When we press test the purple box moves bit not the body inside it ...

Jin
I was able to find solution to this problem , i found the starting point by using this -

trace(level1WorldObj.box1.b2body.GetPosition().x);
trace(level1WorldObj.box1.b2body.GetPosition().y);

then once i had the position manually i took down the coordinates and used the below code ....

level1WorldObj.box1.b2body.SetTransform(new V2(-2, 2),0 );

Thanks @irrestibleforce for all the help ...

Regards
Jin

Original thread: https://box2d.org/forum/viewtopic.php?t=9829