ioscocos2d-xbox2dbox2d-iphone

Movement of Box2d Body in cocos2d-x


I need to move the box2d body according to position received form game center server.

After receiving position I just update the body position using: -

   Carbody->SetTransform(b2Vec2(serverposition.x,serverposition.y),0);

But its moving the body inapprotiate manner (for example. Body is showing somewere lese in the screen). At same time my sprite image not moving (attached with body).


Solution

  • What i did to solve the positioning problem is i taken a normal sprite image and just change position in update with that box2d body position.

    Eg:-

    your carbody movement based on server position. it will move invisibly. your b2body without userdata(image)

    carMainBody->SetTransform(b2Vec2(serverposition,carMainBody->GetPosition().y), 0.0f);
    

    here your normal sprite image. just attch your sprite image like this

     car->setPosition(ccp(carMainBody->GetPosition().x*PTM_RATIO,carMainBody->GetPosition().y*PTM_RATIO));
    

    This method worked fine for me.