我无法在 b2body 上定位 ccsprite。
我想在 box2d 身体上对齐 ccsprite。现在他们之间有差距,我不想要那个差距。
我正在使用 Andreas Loew 的 GB2ShapeCache 来获取身体上的固定装置。
PTM_RATIO = 32
这是我的代码:
string stageName="Stage1";
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCPoint center=ccp((s.width/2),(s.height/2));
CCSprite *sprite = new CCSprite();
sprite->initWithFile("Stage1.png");
sprite->setAnchorPoint(CCPoint(0.50, 0.5));
sprite->setPosition(center);
this->addChild(sprite);
// Define the dynamic body.
//Set up a 1m squared box in the physics world
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.userData=sprite;
bodyDef.position.Set(center.x/PTM_RATIO,center.y/PTM_RATIO);
//bodyDef.position=b2Vec2(10, 10);
b2Body *body = world->CreateBody(&bodyDef);
//adding fixtudre to body
GB2ShapeCache::sharedGB2ShapeCache()->addFixturesToBody(body, "Stage1");
//weld joint at center
b2WeldJointDef *weldJoint= new b2WeldJointDef();
weldJoint->Initialize(groundBody, body, b2Vec2(center.x/PTM_RATIO,center.y/PTM_RATIO));
world->CreateJoint(weldJoint);