如题,感谢。
参考下面的方法获取body以及shapes
ArmatureDataManager::getInstance()->addArmatureFileInfo(“DemoPlayer0.png”,“DemoPlayer0.plist”,“DemoPlayer.ExportJson”);
armature = Armature::create("DemoPlayer");
armature->setPosition(Point(visibleSize.width * 0.8,visibleSize.height * 0.5));
armature->getAnimation()->playByIndex(0);
armature->setScale(0.25);
this->addChild(armature);
// 设置body
auto playerPos = Point(armature->getPositionX(), armature->getPositionY());
b2BodyDef bodyDef2;
bodyDef2.type = b2_dynamicBody;
bodyDef2.position.Set(playerPos.x/PT_RATIO, playerPos.y/PT_RATIO);
bodyDef2.userData = armature;
b2Body *playerBody = world->CreateBody(&bodyDef2);
//playerBody->CreateFixture(&fixtureDef2);
playerBody->SetGravityScale(10);
armature->setBody(playerBody);
// 设置filter
b2Filter filter;
filter.categoryBits = 1;
filter.maskBits = 1;
for (b2Fixture* shapes = armature->getBody()->GetFixtureList(); shapes; shapes = shapes->GetNext())
{
//shapes->SetSensor(true);
shapes->SetDensity(5.0f/CC_CONTENT_SCALE_FACTOR());
shapes->SetRestitution(1.0f);
shapes->SetFriction(0.2f);
shapes->SetFilterData(filter);
}