Sprite and body are not on the same place

Hi,

I add a sprite to the stage and want to give him physics. It works, but the box2d body is not on the same place then the sprite!!

why??

regards

Code:
private function addCircle(tShape:Sprite, tX:Number, tY:Number):void
{
         var tDynamicBody:b2Body;
            
         var tCircle:b2CircleDef = new b2CircleDef();
        tCircle.radius = (tShape.width/2)/pPhysScale;
         tCircle.density = 1;
         tCircle.friction = 0.3;
      tCircle.restitution = 0.2
         
      var tMyBodyDef:b2BodyDef = new b2BodyDef();
      tMyBodyDef.position.Set(tShape.x / pPhysScale, tShape.y / pPhysScale);
         
      tDynamicBody = pWorld.CreateBody(tMyBodyDef);
      tDynamicBody.CreateShape(tCircle);
      tDynamicBody.SetMassFromShapes();
         
      pActor = new Actor(tDynamicBody, tShape);
      tDynamicBody.m_userData = pActor;
      pActors.push(pActor);
         
         drawArea.addChild(tShape);
         }
a testbed example, or even a .swf posted somewhere so people can see what you are talking about. I'd even settle for a screen shot. Have you made sure that your sprite is centered? Have you tried using debug drawing to see where the box2D objects are? giving us code out of context and asking why it doesn't work is not going to help, neither is starting new threads because no one is answering your other one.
sorry ...

I prepared a folder with a swf and the hopefully important methods of code.

to get interaction in the swf you just have to draw a circle by hand.

regards and thanks for the help
this is nothing more than the code you've allready posted...

from the demo that you have, I'd guess that the problem is how you are drawing your shapes. I'm thinking you are creating a new sprite, then using the graphics API to draw the shape using mouse input. Problem is, that shape is now offset from the sprites 0,0 point.( of course, I can't confirm this without your code. Well I can but I don't feel like getting a decompiler to check )

if I draw a circle at 100,100 with radius 20, and then attach it to the box 2d object, it will always be 100,100 pixels offset.
and if you use the sprites position to create the box, that is why its always starting the box2d shape at 0,0.... because that's where your sprite is!!

what you have to do is create the sprite, move it to the mouse position, and then draw your shape centered around that point. So for the circle, you'd set the sprite x and y to 100,100. then draw the circle like this -> sprite.graphics.drawCircle( 0, 0, radius );

Hope that helps.
(btw you can see this must be the case when you make a box and get it to rotate, the drawn shape rotates offset from the b2body)
thats it ... thanks!!

I found it out by myself with your tip in the post before. But your post was 10 seconds before my answer... 😀

all the best niwe

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